处理一对多的映射关系:
- collection
- 分步查询
使用集合在实体类中表示一对多的关系
dart
package com.baidu.mybatis.pojo;
import java.util.List;
public class Dept {
private Integer did;
private String deptName;
private List<Emp> emps;
public Dept() {
}
public Dept(Integer did, String deptName) {
this.did = did;
this.deptName = deptName;
}
public Dept(Integer did, String deptName, List<Emp> emps) {
this.did = did;
this.deptName = deptName;
this.emps = emps;
}
/**
* 获取
* @return did
*/
public Integer getDid() {
return did;
}
/**
* 设置
* @param did
*/
public void setDid(Integer did) {
this.did = did;
}
/**
* 获取
* @return deptName
*/
public String getDeptName() {
return deptName;
}
/**
* 设置
* @param deptName
*/
public void setDeptName(String deptName) {
this.deptName = deptName;
}
/**
* 获取
* @return emps
*/
public List<Emp> getEmps() {
return emps;
}
/**
* 设置
* @param emps
*/
public void setEmps(List<Emp> emps) {
this.emps = emps;
}
public String toString() {
return "Dept{did = " + did + ", deptName = " + deptName + ", emps = " + emps + "}";
}
}
DeptMapper

DeptMapper.xml

测试:


总结
collection:处理一对多的映射关系
ofType:表示该属性所对应的集合中存储数据的类型
