<resultMap id="menuQuery" type="com.wlpy.common.entity.Menu">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="parentId" jdbcType="VARCHAR" property="parentId" />
<result column="menuName" jdbcType="VARCHAR" property="menuName" />
<result column="url" jdbcType="VARCHAR" property="url" />
<result column="type" jdbcType="VARCHAR" property="type" />
<result column="perms" jdbcType="VARCHAR" property="perms" />
<collection property="menuList" select="lowMenu" column="id" ofType="com.wlpy.common.entity.Menu">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="parentId" jdbcType="VARCHAR" property="parentId" />
<result column="menuName" jdbcType="VARCHAR" property="menuName" />
<result column="url" jdbcType="VARCHAR" property="url" />
<result column="type" jdbcType="VARCHAR" property="type" />
<result column="perms" jdbcType="VARCHAR" property="perms" />
</collection>
</resultMap>
<select id="findAllMenu" parameterType="java.util.Map" resultMap="menuQuery">
SELECT
m.id,
m.parent_id AS parentId,
m.menu_name AS menuName,
m.url,
m.type,
m.perms
FROM
menu AS m
WHERE
m.available = 1
AND m.parent_id = 0
</select>
<select id="lowMenu" parameterType="java.util.Map" resultMap="menuQuery">
SELECT
m.id,
m.parent_id AS parentId,
m.menu_name AS menuName,
m.url,
m.type,
m.perms
FROM
menu AS m
WHERE
m.available = 1
AND m.parent_id = #{id} 父级ID
</select>
mybatis查询树形菜单sql效率低
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
5条回答 默认 最新
- CSDN专家-sinJack 2021-08-18 14:37关注
我看sql也不复杂,是查询慢吗,看下索引使用情况。
执行计划:explain sql语句本回答被题主选为最佳回答 , 对您是否有帮助呢?评论 打赏 举报解决 1无用