41 lines
1.6 KiB
XML
41 lines
1.6 KiB
XML
|
<?xml version="1.0" encoding="UTF-8"?>
|
||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||
|
<mapper namespace="com.dite.znpt.mapper.MenuMapper">
|
||
|
|
||
|
|
||
|
<select id="upwardRecursionSelect" resultType="com.dite.znpt.domain.entity.MenuEntity">
|
||
|
WITH RECURSIVE MenuPath AS (
|
||
|
SELECT * FROM menu
|
||
|
<where>
|
||
|
<choose>
|
||
|
<when test="menuName != null and menuName != ''">
|
||
|
AND menu_name LIKE concat('%',#{menuName}, '%') -- 起始菜单
|
||
|
</when>
|
||
|
<otherwise>
|
||
|
AND parent_id = '0' -- 起始菜单
|
||
|
</otherwise>
|
||
|
</choose>
|
||
|
</where>
|
||
|
UNION ALL
|
||
|
SELECT m.* FROM menu m INNER JOIN MenuPath mp ON m.menu_id = mp.parent_id
|
||
|
) SELECT DISTINCT * FROM MenuPath;
|
||
|
</select>
|
||
|
|
||
|
<select id="downwardRecursionSelect" resultType="com.dite.znpt.domain.entity.MenuEntity">
|
||
|
WITH RECURSIVE SubMenus AS (
|
||
|
SELECT * FROM menu
|
||
|
<where>
|
||
|
<choose>
|
||
|
<when test="menuId != null and menuId != ''">
|
||
|
AND menu_id = #{menuId} -- 起始菜单ID
|
||
|
</when>
|
||
|
<otherwise>
|
||
|
AND parent_id = '0' -- 起始菜单
|
||
|
</otherwise>
|
||
|
</choose>
|
||
|
</where>
|
||
|
UNION ALL
|
||
|
SELECT d.* FROM menu d INNER JOIN SubMenus sd ON d.parent_id = sd.menu_id
|
||
|
) SELECT * FROM SubMenus;
|
||
|
</select>
|
||
|
</mapper>
|