1、entity 中加入childrenMenu
@DATA
public class SysMenu implements Serializable {
private static final long serialVersionUID = -85892554078912581L;
/**
* 编号
*/
@TableId(type = IdType.ASSIGN_ID)
private Long id;
/**
* 父级编号
*/
private Long parentId;
/**
* 名称
*/
private String name;
private List<SysMenu> childrenMenu;
2、Mapper中修改resultMap ,加上collection
<resultMap type="com.xiaoli.mcc.system.entity.SysMenu" id="SysMenuMap">
<result property="id" column="id" jdbcType="INTEGER"/>
<result property="parentId" column="parent_id" jdbcType="INTEGER"/>
<result property="name" column="name" jdbcType="VARCHAR"/>
<result property="type" column="type" jdbcType="INTEGER"/>
<result property="sort" column="sort" jdbcType="INTEGER"/>
<result property="href" column="href" jdbcType="VARCHAR"/>
<result property="icon" column="icon" jdbcType="VARCHAR"/>
<result property="category" column="category" jdbcType="INTEGER"/>
<result property="permission" column="permission" jdbcType="VARCHAR"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
<collection column="id" property="childrenMenu" ofType="com.xiaoli.mcc.system.entity.SysMenu" select="selectNodeByParentId" ></collection>
</resultMap>
3、Mapper中加入connection的selectNodeByParentId,resultMap使用上面定义的resultMap。
<select id="selectNodeByParentId" parameterType="java.lang.Long" resultMap="SysMenuMap">
select
*
from
sys_menu
where
parent_id = #{id}
order by sort
</select>
4、开始写自己的查询,只需将查出父id,resultMap使用上面定义的resultMap。
<select id="selectWmsPcAllTreeNotOne" resultMap="SysMenuMap">
select *
from sys_menu
where parent_id = 0 and category = 1 and type = 1
order by sort
</select>