mybatis查询树结构

mapper配置

  1. 结果集配置
    <resultMap id="MenuContents" type="com.phfund.micro.dto.DmspIndexMenuDTO">
        <result column="MENU_CODE" jdbcType="VARCHAR" property="menuCode" />
        <result column="MENU_NAME" jdbcType="VARCHAR" property="menuName" />
        <result column="MENU_FLAG" jdbcType="VARCHAR" property="menuflag" />
        <collection property="IndexMenu" ofType="com.phfund.micro.dto.DmspIndexMenuDTO" column="MENU_CODE" select="queryMenuChildContents"/>
    </resultMap>
    <resultMap id="MenuchildMap" type="com.phfund.micro.dto.DmspIndexMenuDTO">
        <result column="MENU_CODE" jdbcType="VARCHAR" property="menuCode" />
        <result column="MENU_NAME" jdbcType="VARCHAR" property="menuName" />
        <result column="MENU_FLAG" jdbcType="VARCHAR" property="menuflag" />
        <collection property="IndexMenu" ofType="com.phfund.micro.dto.DmspIndexMenuDTO" column="MENU_CODE" select="queryMenuSonContents"/>
    </resultMap>
    <resultMap id="sonContentsMenuMap" type="com.phfund.micro.dto.DmspIndexMenuDTO">
        <result column="MENU_CODE" jdbcType="VARCHAR" property="menuCode" />
        <result column="MENU_NAME" jdbcType="VARCHAR" property="menuName" />
        <result column="MENU_FLAG" jdbcType="VARCHAR" property="menuflag" />
    </resultMap>

2.SQL语句配置

    <select id="queryMenuContents" resultMap="MenuContents">
        select MENU_CODE,MENU_NAME,'0' as MENU_FLAG from DMSP_INDEX_MENU where PARENT_MENU_CODE='root' order by MENU_ORDER
    </select>
    <select id="queryMenuChildContents" resultMap="MenuchildMap">
        select MENU_CODE,MENU_NAME ,'0' as MENU_FLAG,MENU_ORDER from DMSP_INDEX_MENU where PARENT_MENU_CODE=#{menuCode,jdbcType=VARCHAR}
    </select>
    <select id="queryMenuSonContents" resultMap="sonContentsMenuMap">
        select MENU_CODE,MENU_NAME ,'0' as MENU_FLAG,MENU_ORDER from DMSP_INDEX_MENU where PARENT_MENU_CODE=#{menuCode,jdbcType=VARCHAR}
    </select>

3.部分解释
< collection property=“IndexMenu” ofType=“com.phfund.micro.dto.DmspIndexMenuDTO” column=“MENU_CODE” select=“queryMenuChildContents”/>
property:表示对应实体类中的属性 List<?> 类型
ofType:实体类
column:结果集中的字段,也就是查询所对应的参数值
select :对应的查询语句 queryMenuChildContents为对应语句的id

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值