Mybatis之association和collection

1.单个关联查询association

1.1实体之间的关联表示

package com.worldly.config.entity;

import java.io.Serializable;

/**
 * @Description
 * @Author xiaoqx <worldly_xuan@163.com>
 * @Version V1.0.0
 * @Since 2017/11/26
 */
public class Employee implements Serializable {
   
   
    private Integer id;
    private String name;
    private String email;
    private String tel;
    //关联的部门实体,查询某个人的时候可以把所在部门信息查询出来
    private Department dep;


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    public Department getDep() {
        return dep;
    }

    public void setDep(Department dep) {
        this.dep = dep;
    }

    @Override
    public String toString() {
        return "{\"Employee\":{"
                + "\"id\":\"" + id + "\""
                + ", \"name\":\"" + name + "\""
                + ", \"email\":\"" + email + "\""
                + ", \"tel\":\"" + tel + "\""
                + ", \"dep\":" + dep
                + "}}";
    }
}

1.2 两种关联查询方式

//第一中方式:直接进行关联查询把关联实体的属性在xml中配置
//然后关联查出来
<resultMap id="emp2ResultMap" type="com.worldly.config.entity.Employee">
        <id column="emp_id" property="id"></id>
        <result column="emp_name" property="name"/>
        <result column="emp_email" property="email"/>
        <result column="emp_tel" 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值