• 自定义ResultMap查询,这里的关联写法只能用于不分页


    <?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="org.sang.mapper.MenuMapper">
        <resultMap id="BaseResultMap" type="org.sang.bean.Menu">
            <id column="id" property="id" jdbcType="INTEGER"/>
            <result column="url" property="url" jdbcType="VARCHAR"/>
            <result column="path" property="path" jdbcType="VARCHAR"/>
            <result column="component" property="component" javaType="java.lang.Object"/>
            <result column="name" property="name" jdbcType="VARCHAR"/>
            <result column="iconCls" property="iconCls" jdbcType="VARCHAR"/>
            <result column="keepAlive" property="keepAlive" jdbcType="BIT"/>
            <result column="parentId" property="parentId" jdbcType="INTEGER"/>
            <association property="meta" javaType="org.sang.bean.MenuMeta">
                <result column="keepAlive" property="keepAlive"/>
                <result column="requireAuth" property="requireAuth"/>
            </association>
            <collection property="roles" ofType="org.sang.bean.Role">
                <id column="rid" property="id"/>
                <result column="rname" property="name"/>
                <result column="rnamezh" property="nameZh"/>
            </collection>
            <collection property="children" ofType="org.sang.bean.Menu">
                <id column="id2" property="id"/>
                <result column="path2" property="path" jdbcType="VARCHAR"/>
                <result column="component2" property="component" jdbcType="VARCHAR"/>
                <result column="name2" property="name" jdbcType="VARCHAR"/>
                <result column="iconCls2" property="iconCls" jdbcType="VARCHAR"/>
                <association property="meta" javaType="org.sang.bean.MenuMeta">
                    <result column="keepAlive2" property="keepAlive"/>
                    <result column="requireAuth2" property="requireAuth"/>
                </association>
                <collection property="children" ofType="org.sang.bean.Menu">
                    <id column="id3" property="id"/>
                    <result column="name3" property="name" jdbcType="VARCHAR"/>
                </collection>
            </collection>
        </resultMap>
        <select id="getAllMenu" resultMap="BaseResultMap">
            select m.*,r.`id` as rid,r.`name` as rname,r.`nameZh` as rnamezh from menu m left join menu_role mr on m.`id`=mr.`mid` left join role r on mr.`rid`=r.`id` WHERE m.`enabled`=true order by m.`id` desc
        </select>
        <select id="getMenusByHrId" parameterType="Long" resultMap="BaseResultMap">
            select m1.`id`,m1.`path`,m1.`component`,m1.`iconCls`,m1.`name`,m1.`requireAuth`,m2.`component` as component2,m2.`iconCls` as iconCls2,m2.`keepAlive` as keepAlive2,m2.`name` as name2,m2.`path` as path2,m2.`requireAuth` as requireAuth2 from menu m1,menu m2 where m1.`id`=m2.`parentId` and m1.`id`!=1 and m2.`id` in(select mr.`mid` from hr_role h_r,menu_role mr where h_r.`rid`=mr.`rid` and h_r.`hrid`=#{hrId}) and m2.`enabled`=true order by m1.`id`,m2.`id`
        </select>
        <select id="menuTree" resultMap="BaseResultMap">
                select m1.`id`,m1.`name`,m2.`id` as id2,m2.`name` as name2,m3.`id` as id3,m3.`name` as name3 from menu m1,menu m2,menu m3 where m1.`id`=m2.`parentId` and m2.`id`=m3.`parentId` and m3.`enabled`=true
            </select>
        <select id="getMenusByRid" resultType="Long">
            SELECT mid from menu_role WHERE rid=#{rid}
        </select>
    </mapper>
    

      

  • 相关阅读:
    docker镜像
    docker常用命令
    docker基础
    跨站脚本漏洞(XSS)基础
    Session、Cookie与Token
    linux之curl工具
    ssl证书与java keytool工具
    mysql主从复制
    linux之平均负载(学习笔记非原创)
    mysql8.0忘记密码如何操作?
  • 原文地址:https://www.cnblogs.com/qq1069284034/p/11466317.html
Copyright © 2020-2023  润新知