自定义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>
自定义ResultMap查询,这里的关联写法只能用于不分页的更多相关文章
- Spring Boot入门系列(十七)整合Mybatis,创建自定义mapper 实现多表关联查询!
之前讲了Springboot整合Mybatis,介绍了如何自动生成pojo实体类.mapper类和对应的mapper.xml 文件,并实现最基本的增删改查功能.mybatis 插件自动生成的mappe ...
- Spring Security教程(二):自定义数据库查询
Spring Security教程(二):自定义数据库查询 Spring Security自带的默认数据库存储用户和权限的数据,但是Spring Security默认提供的表结构太过简单了,其实就 ...
- Hibernate原生SQL查询多表关联,SQL语句要注意的问题
Hibernate原生SQL查询多表关联,SQL语句要注意的问题 @for&ever 2009-9-4 系统环境: MySQL5.1 Hibernate3.3 有如下的假定: 实体类 Ques ...
- Hibernate自定义字段查询
关于Hibernate自定义字段查询的方法,网上有很多,我这里就不详细写了,只把几个查询方法的注意事项说明一下. 废话少说, 进入正题: 假设有2个实体对象,Institution和User,结构与配 ...
- atitit. 集合groupby 的实现(2)---自定义linq查询--java .net php
atitit. 集合groupby 的实现(2)---自定义linq查询--java .net php 实现方式有如下 1. Linq的实现原理流程(ati总结) 1 2. groupby 与 事 ...
- jeecg自定义datagrid查询
为什么要写这篇文章? 我们了解,使用 jeecg 提供的 CriteriaQuery 查询方式,确实能满足绝大数的需求,但是往往有那么个比较复杂的情况,需要我们直接去写 sql,比如多表查询呀等等等等 ...
- SQL基础教程(第2版)第5章 复杂查询:5-3 关联子查询
第5章 复杂查询:5-3 关联子查询 ● 关联子查询会在细分的组内进行比较时使用.● 关联子查询和GROUP BY子句一样,也可以对表中的数据进行切分.● 关联子查询的结合条件如果未出现在子查询之中就 ...
- webservice 测试窗体只能用于来自本地计算机的请求
Question: WebService部署成站点之后,如果在本地测试webservice可以运行,在远程却显示“测试窗体只能用于来自本地计算机的请求”或者"The test form is ...
- 解决WebService 测试窗体只能用于来自本地计算机的请求
问题: 今天上 午,WebService部署成站点之后,如果在本地测试webservice可以运行,在远程却显示“测试窗体只能用于来自本地计算机的请求”或 者"The test form i ...
随机推荐
- MQTT 连接服务端失败,报错客户机未连接(32104)
和同事协同开发项目,在启动项目时偶尔报错连接不到MQTT 服务器. 原因是两个人开发同一个项目,连接MQTT时配置的 client-id 相同,在使用一个client-id连接到MQTT服务器后,再使 ...
- Docker部署测试
安装虚拟机 准备一台Centos7的VM,名为Centos7-1 具体过程可以参考: KVM安装 KVM——以桥接的方式搭建虚拟机网络配置 安装Docker 下载rpm包:https://downlo ...
- 定时任务-Quartz(热部署、冷部署)
一.配置Quartz.xml <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context ...
- vue调试工具vue-devtools安装
vue-devtools是一款基于chrome浏览器的插件,用于vue应用的调试,这款vue调试神器可以极大地提高我们的调试效率.帮助我们快速的调试开发vue应用. 这里介绍一下vue-devtool ...
- 软件-效率:Microsoft To Do
ylbtech-软件-效率:Microsoft To Do Microsoft To Do To Do 让你从工作到娱乐都保持专注. 1.返回顶部 1. 智能每日计划 使用“我的一天”,用智能个性化建 ...
- 八十四:redis之redis的集合、哈希操作
set集合操作 添加元素:sadd set value1 value2... 查看元素:smembers set 移除元素:srem set member 查看集合中的元素个数:scard set 获 ...
- kvm网络虚拟化(vlan,bond,vlan+bond)(3)
一.Linux Bridge网桥管理 网络虚拟化是虚拟化技术中最复杂的部分,也是非常重要的资源. VM2 的虚拟网卡 vnet1 也连接到了 br0 上. 现在 VM1 和 VM2 之间可以通信,同时 ...
- WebJars简介
https://www.cnblogs.com/liaojie970/p/7852576.html https://blog.csdn.net/eff666/article/details/70183 ...
- <li>元素的排序
要点: getElementsByTagName("li")返回的是HTMLCollection对象,这个对象不同于Array对象,不能使用sort()方法进行排序~ 下面方法的要 ...
- CSS练习-导航栏斜线分隔-利用伪元素
开始切第一张图了,第一个遇到的问题是顶部导航栏这里,用斜线分割.想到的思路是用伪类:before或者:after实现 先写html结构. <!-- 导航栏begin --> <div ...