mybatis-association 阳光穿透心脏的1/2处 2022-06-02 03:49 185阅读 0赞 > 描述: 员工类(Employee) 中有 部门类(Dept) @Data @ToString public class Employee { private Integer id; private String last_name; private String emaile; private String gender; private Dept dept; } @Data public class Dept { private Integer id; private String dept_name; } <resultMap id="MyMap" type="com.example.demo.entity.Employee"> <id column="id" property="id"/> <result column="last_name" property="last_name"/> <result column="gender" property="gender"/> <result column="emaile" property="emaile"/> <!--<result column="did" property="dept.id"/>--> <!--<result column="dept_name" property="dept.dept_name"/>--> <association property="dept" javaType="com.example.demo.entity.Dept"> <id column="id" property="id"/> <result column="dept_name" property="dept_name"/> </association> </resultMap> <select id="findeptAnfEmp" resultMap="MyMap"> SELECT * FROM tbl_employee e LEFT JOIN tbl_dept d ON e.d_id =d.id </select> ================================== [Employee(id=1, last_name=tom, emaile=tom@163.com, gender=1, dept=Dept(id=1, dept_name=kaifa)), Employee(id=3, last_name=zhangsan, emaile=123.163.com, gender=1, dept=Dept(id=3, dept_name=kaifa)), Employee(id=5, last_name=lisi, emaile=lisi.163.com, gender=0, dept=Dept(id=5, dept_name=kaifa)), Employee(id=2, last_name=dom, emaile=dom.qq.com, gender=0, dept=Dept(id=2, dept_name=ceshi)), Employee(id=4, last_name=lisi, emaile=lisi.163.com, gender=0, dept=Dept(id=4, dept_name=ceshi)), Employee(id=6, last_name=lisi, emaile=lisi.163.com, gender=0, dept=Dept(id=6, dept_name=ceshi))]
还没有评论,来说两句吧...