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
因为一直想着这个问题,做梦想到了这个问题的关键
<!-- 查询一级菜单权限返回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 构造查询和联合子查询问题
- mybatis查询参数为0且类型不是string的小问题
- 关于mybatis只能查询英文,不能查询中文的问题!!!
- 在论坛中出现的比较难的sql问题:28(循环查询表来实现递归)
- Mybatis学习笔记-关联表查询的问题 (一对多关联)
- Mybatis like 模糊查询问题
- mybatis模糊查询问题
- 在最近做一个高级查询时遇见的问题,javascript在动态的form里使用会出现问题
- mybatis查询列表时,domain的setter方法问题
- 关于Mybatis 中模糊查询查找不到Mysql数据库的内容的问题
- MyBatis-模糊查询控制台不报错,但是得到的结果集合确是0的问题解决办法
- mybatis条件查询容易遇见的错误
- 解决:Mybatis无法查询中文问题
- mybatis查询sql:where语句“查询时间字段书写问题”引发的索引失效
- Mybatis事务下解决多次select语句查询结果一致的问题+案列(获取全局序列ID)
- 在使用Mybatis 做查询时遇到查询到的对象为空的问题
- mybatis执行两次相同的查询问题
- mybatis使用foreach批次插入,解决sequence只查询一次的问题(在此,我只看union all 部分)
- 问题:mybatis查询无结果集,但数据库执行相同的sql有结果集
- 使用mybatis遇到的关于条件查询">"以及if test传参的使用问题