mybatis-collection - 日理万妓 2022-06-02 04:17 138阅读 0赞 ### mybatis-collection 标签的使用 ### @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; private List<Employee> employeeList; } <resultMap id="MyDept" type="com.example.demo.entity.Dept"> <id column="id" property="id"/> <result column="dept_name" property="dept_name"/> <collection property="employeeList" column="id" select="com.example.demo.mapper.EmployeeMapper.selec"> </collection> </resultMap> <select id="findDept" resultMap="MyDept"> SELECT id,dept_name FROM tbl_dept </select> <select id="selec" resultType="com.example.demo.entity.Employee" parameterType="integer"> SELECT * FROM tbl_employee where d_id=#{id} </select> 方式2; <resultMap id="ms1" type="com.example.demo.entity.Dept"> <id column="did" property="id"/> <result column="dept_name" property="dept_name"/> <collection property="employeeList" ofType="com.example.demo.entity.Employee"> <id column="eid" property="id"/> <result column="last_name" property="last_name"/> <result column="emaile" property="emaile"/> </collection> </resultMap> <select id="s1" resultMap="ms1"> SELECT d.id did,d.dept_name, e.id eid ,e.emaile,e.last_name FROM tbl_dept d LEFT JOIN tbl_employee e ON d.id=e.d_id </select>
还没有评论,来说两句吧...