<resultMap type="com.rr.one2many.Department" id="deptMap">
<id property="id" column="id"/>
<result property="name" column="name"/>
<!-- <collection property="emps" ofType="com.rr.one2many.Employee" javaType="java.util.ArrayList" column="id" select="empNamespace.findEmpById"></collection>
-->
<collection property="emps" column="id" select="findEmpById" ></collection>
</resultMap>
<select id="findAll" resultType="com.rr.one2many.Department">
select * from department
</select>
<select id="findById" parameterType="int" resultType="com.rr.one2many.Department">
select id,name from department where id=#{id}
</select>
<select id="findEmpById" parameterType="int" resultType="com.rr.one2many.Employee">
select * from employee where depId=#{id}
</select>
<select id="findEmpById" parameterType="int" resultType="com.rr.one2many.Employee">
select * from employee where depId=#{id}
</select>
<select id="findEmpByEmpId" parameterType="int" resultType="com.rr.one2many.Employee">
select id,name,depId from employee where id=#{id}
</select>
<resultMap type="com.rr.one2many.Employee" id="empMap">
<id property="id" column="id"/>
<result property="name" column="name"/>
<result property="age" column="age"/>
<association property="dept" javaType="com.rr.one2many.Department" column="depId" select="deptNamespace.findById"></association>
</resultMap>
员工表和部门表,查询部门时,获取关联的员工,或者查询员工时,获取关联的部门。但是执行某个select时,不会执行关联select。
比如,执行findEmpByEmpId,但是assocation中select对应的deptNamespace.findById"不执行
没有使用懒加载