您的位置:首页 > 其它

Mybatis 递归子查询遇见的问题

2018-01-31 12:08 357 查看
在运用Springboot +springcloud+mybatis项目中,在菜单列表的三级查询中运用到mybatis递归子查询,然而在查询的时候,有好几次只执行了第一次查询,第二次子菜单不显示。

因为一直想着这个问题,做梦想到了这个问题的关键

<!-- 查询一级菜单权限返回VOTwo -->

 <resultMap id="allMenuMap" type="net.cqnews.hlzycf.common.vo.MenuVO">

  <id property="strMenuId" column="strMenuId" /> <!-- 菜单ID -->

  <result property="strMenuName" column="strMenuName"/> <!-- 菜单名称 -->

  <result property="strMenuIcon" column="strMenuIcon"/> <!-- 菜单图标 -->

  <result property="strMenuIconValue" column="strMenuIconValue"/> <!-- 菜单图标值 -->

  <result property="strMenuUrl" column="strMenuUrl"/> <!-- 路径-->

  <result property="strMenuStatus" column="strMenuStatus"/> <!-- 菜单状态 -->

  <collection property="childList" column="strMenuId" select="twoMenuByPid" /> <!-- 子菜单 -->

 </resultMap>

 

 <!-- 查询所有菜单权限 -->

 <select id="listMenu" parameterType="string" resultMap="allMenuMap">

     SELECT strMenuId, strMenuName, strMenuIcon, strMenuIconValue, strMenuUrl, strMenuStatus FROM tb_menu

  WHERE strOrgStructCode=#{strOrgStructCode} AND strMenuPid='' ORDER BY intSortWeight, strLevelCode

 </select>

 <!-- 根据父ID查询二级菜单权限 -->

 <select id="twoMenuByPid" parameterType="string" resultMap="allMenuMap">

     SELECT strMenuId, strMenuName, strMenuIcon, strMenuIconValue, strMenuUrl, strMenuStatus FROM tb_menu

  WHERE strMenuPid=#{strMenuId} ORDER BY intSortWeight, strLevelCode

 </select> 

这里在collection调用方法里面的column值需要在map里面定义清楚,如果不定义,子查询将不执行,在定义这个property的时候,还需要实体类有定义。

 更多技术交流QQ群:260292706
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mybatis