mybatis-查询(resultMap,关联集合)-15

mybatis更多资料请访问 www.itkc8.com

 

场景:查询部门下的所有员工

第一种方式:嵌套结果集方式 
第二种方式:分步查询方式

第一种方式:嵌套结果集方式
javaBean

public class Department {
    private Integer id;
    private String name;
    private List employees;}

接口

public Department getDepartmentByIdPlus(Integer id);
1
sql映射文件

   
       
       
       
           
           
           
           
               
               
               
               
           

       

       

junit

 DepartmentMapper mapper = session.getMapper(DepartmentMapper.class);
                Department dept = mapper.getDepartmentByIdPlus(2);// 分步查询
                System.out.println(dept.toString());
                System.out.println(dept.getEmployees());
// Department{id=2, name='ceshi'}[Employee{id=1, //lastName='Jerry', email='[email protected]', gender='1'}, //Employee{id=3, lastName='Jerry', email='[email protected]', //gender='1'}]

第二种方式:分步查询方式
public Department getDepartmentByIdStep(Integer id);
1

       
           
           
                                column="id">
           

       

       

 Department dept = mapper.getDepartmentByIdStep(2);// 分步查询  collection
//Department{id=2, name='ceshi'}
//[Employee{id=1, lastName='null', email='[email protected]', gender='1'}, Employee{id=3, lastName='null', email='[email protected]', gender='1'}]
 

更多资料请访问 www.itkc8.com

https://blog.csdn.net/apple_5/article/details/72953946

你可能感兴趣的:(Mybatis)