用户信息类
部门:
package com.atguigu.mybatis.pojo; import java.util.List; public class Dept { private int deptId; private String deptName; public Dept(){} public Dept(int deptId, String deptName, List<Emp> emps) { this.deptId = deptId; this.deptName = deptName; } public int getDeptId() { return deptId; } public void setDeptId(int deptId) { this.deptId = deptId; } public String getDeptName() { return deptName; } public void setDeptName(String deptName) { this.deptName = deptName; } @Override public String toString() { return "Dept{" + "deptId=" + deptId + ", deptName='" + deptName + '\'' + '}'; } }
员工信息:
package com.atguigu.mybatis.pojo; public class Emp { private int empId; private String empName; private int age; private String gender; private Dept dept; public Emp(){} public Emp(int empId, String empName, int age, String gender, Dept dept) { this.empId = empId; this.empName = empName; this.age = age; this.gender = gender; this.dept = dept; } public int getEmpId() { return empId; } public void setEmpId(int empId) { this.empId = empId; } public String getEmpName() { return empName; } public void setEmpName(String empName) { this.empName = empName; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } public Dept getDept() { return dept; } public void setDept(Dept dept) { this.dept = dept; } @Override public String toString() { return "Emp{" + "empId=" + empId + ", empName='" + empName + '\'' + ", age=" + age + ", gender='" + gender + '\'' + ", dept=" + dept + '}'; } }
sql表:
mapper接口:
xml文件
collection:
查询当前部门下所有员工信息
mapper集合
用户信息类添加:
sql:
如果使用resultmap需要重新指定一个id 用上文的id会报错栈溢出。、
懒加载: