mybatis懒加载
mybatis懒加载全局配置
<settings> <setting name="mapUnderscoreToCamelCase" value="true"/> <!--开启懒加载(开启延迟加载)--> <setting name="lazyLoadingEnabled" value="true"/> <!--关闭实时加载--> <setting name="aggressiveLazyLoading" value="false"/> </settings>
<resultMap id="empAndDeptByStepResultMap" type="emp"> <id column="emp_id" property="empId"></id> <result column="emp_name" property="empName"></result> <result column="age" property="age"></result> <result column="gender" property="gender"></result> <!-- fetchType:lazy懒加载,eager立即加载 --> <association property="dept" column="dept_id" select="org.example.mapper.DeptMapper.getEmpAndDeptByStepTwo" fetchType="lazy"> <id column="dept_id" property="deptId"></id> <result column="dept_name" property="deptName"></result> </association> </resultMap>