第一种方式在mybatis中使用collection的递归,之前误以为collection就是一个循环会自动完成递归查询,其实不然,collection设计初衷只是完成关联查询,所以限制了colleciton只是执行一次。解决办法:在collection的select语句中再次调用一个resultMap以便完成递归:
<select id="getFunctions" resultType="brilliance.znjt.business.systemmgr.entity.FunctionEntity" resultMap="functionChildResultMap">
select xtgn.function_no functionNo,xtgn.function_name functionName,xtgn.parent_no parentNo,xtgn.path,xtgn.description,xtgn.type,xtgn.sortid,xtgn.create_time createTime FROM ZNJTMGR.T_SRC_XTGN xtgn where xtgn.function_no in
(
select gn.function_no from ZNJTMGR.R_JS_GN gn where gn.role_no in
(
select js.role_no from ZNJTMGR.R_YH_JS js where js.system_user=#{user}
)
)
and xtgn.type in ('2')
order by sortid,functionNo
</select>
<resultMap type="brilliance.znjt.business.systemmgr.entity.FunctionEntity" id="function