如
Department {
Department parentDepartment;
}
如果设置查询映射
<!--查看指定部门-->
<select id="selectDepartmentByPrimaryKey" resultMap="departmentResult" parameterClass="integer">
select DEPARTMENTID, SCHOOLID, PDEPARTMENTID,DEPARTMENTNAME, DEPARTMENTDESCRIBE, DEPARTMENTCODE
from S_DEPARTMENT
where DEPARTMENTID = #departmentId#
</select>
<resultMap id="departmentResult" class="org.dreamfly.core.model.Department">
<result property="departmentId" column="DEPARTMENTID"/>
<result property="school" column="SCHOOLID" select="selectSchoolByPrimaryKey"/>
<result property="pdepartment" column="PDEPARTMENTID" select="[color=red]selectDepartmentByPrimaryKey[/color]"/>
<result property="departmentName" column="DEPARTMENTNAME"/>
<result property="departmentDescribe" column="DEPARTMENTDESCRIBE"/>
<result property="departmentCode" column="DEPARTMENTCODE" />
</resultMap>
这样会导致查询进入死循环.查询会一直查找他的父部门类
解决方案
<resultMap id="departmentResult" class="org.dreamfly.core.model.Department">
<result property="departmentId" column="DEPARTMENTID"/>
<result property="school" column="SCHOOLID" select="selectSchoolByPrimaryKey"/>
<result property="pdepartment" column="PDEPARTMENTID" select="[color=red]selectParentDepartmentByPrimaryKey[/color]"/>
<result property="departmentName" column="DEPARTMENTNAME"/>
<result property="departmentDescribe" column="DEPARTMENTDESCRIBE"/>
<result property="departmentCode" column="DEPARTMENTCODE" />
</resultMap>
加上一个
<!--查询上级部门,不查询上级部门的上级部门-->
<select id="selectParentDepartmentByPrimaryKey" resultClass="org.dreamfly.core.model.Department" parameterClass="integer"
cacheModel="otherCodeCache">
select DEPARTMENTID, DEPARTMENTNAME, DEPARTMENTDESCRIBE, DEPARTMENTCODE
from S_DEPARTMENT
where DEPARTMENTID = #departmentId#
</select>
Department {
Department parentDepartment;
}
如果设置查询映射
<!--查看指定部门-->
<select id="selectDepartmentByPrimaryKey" resultMap="departmentResult" parameterClass="integer">
select DEPARTMENTID, SCHOOLID, PDEPARTMENTID,DEPARTMENTNAME, DEPARTMENTDESCRIBE, DEPARTMENTCODE
from S_DEPARTMENT
where DEPARTMENTID = #departmentId#
</select>
<resultMap id="departmentResult" class="org.dreamfly.core.model.Department">
<result property="departmentId" column="DEPARTMENTID"/>
<result property="school" column="SCHOOLID" select="selectSchoolByPrimaryKey"/>
<result property="pdepartment" column="PDEPARTMENTID" select="[color=red]selectDepartmentByPrimaryKey[/color]"/>
<result property="departmentName" column="DEPARTMENTNAME"/>
<result property="departmentDescribe" column="DEPARTMENTDESCRIBE"/>
<result property="departmentCode" column="DEPARTMENTCODE" />
</resultMap>
这样会导致查询进入死循环.查询会一直查找他的父部门类
解决方案
<resultMap id="departmentResult" class="org.dreamfly.core.model.Department">
<result property="departmentId" column="DEPARTMENTID"/>
<result property="school" column="SCHOOLID" select="selectSchoolByPrimaryKey"/>
<result property="pdepartment" column="PDEPARTMENTID" select="[color=red]selectParentDepartmentByPrimaryKey[/color]"/>
<result property="departmentName" column="DEPARTMENTNAME"/>
<result property="departmentDescribe" column="DEPARTMENTDESCRIBE"/>
<result property="departmentCode" column="DEPARTMENTCODE" />
</resultMap>
加上一个
<!--查询上级部门,不查询上级部门的上级部门-->
<select id="selectParentDepartmentByPrimaryKey" resultClass="org.dreamfly.core.model.Department" parameterClass="integer"
cacheModel="otherCodeCache">
select DEPARTMENTID, DEPARTMENTNAME, DEPARTMENTDESCRIBE, DEPARTMENTCODE
from S_DEPARTMENT
where DEPARTMENTID = #departmentId#
</select>