分段查询:
问题:查出员工表的信息,以及员工所对应的部门信息
分两段
1.查出员工表的信息
2.查出员工表里部门id所对应具体部门的信息。
Emp getEmpInfo(@Param(“eid”) Integer eid);
下面的dept属性是一个对象,我们需要对这个对象在进行一次查询,查询的内容就是它这张表里的所有信息,根据我们员工表的部门id去查询。
Dept getDeptInfo(@Param("did") Integer did);
测试
开启延迟加载就意味着,你具体查哪个属性,他就会执行哪个属性的具体sql,而不会全部都运行,如果你不开延迟加载,就意味着,你写的sql都会被执行。
一对多如何查询?
一对多,分布查询:
package com.zhang.mapper;
import com.zhang.pojo.Dept;
import org.apache.ibatis.annotations.Param;
public interface DeptMapper {
Dept getDeptInfo(@Param("did") Integer did);
Dept getDeptAndEmp(@Param("did") Integer did);
Dept getDeptANDAllEmp(@Param("did") Integer did);
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface EmpMapper {
List getAllEmp();
Emp getEmpInfo(@Param("eid") Integer eid);
List getEmpAll(@Param("did") Integer did);
select * from t_dept where d_id=#{did};



