<?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.xx.springboot.business.system.dao.UserDao"><resultMap id="UserDtoMap" type="com.xx.springboot.business.system.dto.UserDto"><id column="id" property="id" jdbcType="BIGINT"/><result column="open_id" property="openId" jdbcType="VARCHAR"/><result column="user_code" property="userCode" jdbcType="VARCHAR"/><result column="account" property="account" jdbcType="VARCHAR"/><result column="salt" property="salt" jdbcType="VARCHAR"/><result column="department_id" property="departmentId" jdbcType="VARCHAR"/><result column="department_name" property="departmentName" jdbcType="VARCHAR"/><result column="real_name" property="realName" jdbcType="VARCHAR"/><result column="age" property="age" jdbcType="BIGINT"/><result column="sex" property="sex" jdbcType="BIGINT"/><result column="phone" property="phone" jdbcType="VARCHAR"/><result column="phone" property="phone" jdbcType="VARCHAR"/><result column="id_card_num" property="idCardNum" jdbcType="VARCHAR"/><result column="email" property="email" jdbcType="VARCHAR"/><result column="address" property="address" jdbcType="VARCHAR"/><result column="create_user_id" property="createUserId" jdbcType="BIGINT"/><result column="modified_user_id" property="modifiedUserId" jdbcType="BIGINT"/><result column="gmt_create" property="gmtCreate" jdbcType="TIMESTAMP"/><result column="gmt_modified" property="gmtModified" jdbcType="TIMESTAMP"/><result column="is_deleted" property="isDeleted" jdbcType="TINYINT"/><collection property="roleDOList" columnPrefix="sr_" resultMap="RoleMap"/><collection property="organizationDOList" columnPrefix="so_" resultMap="OrganizationMap"/></resultMap><resultMap id="RoleMap" type="com.xx.springboot.business.system.domain.SysRoleDO"><id column="id" property="id" jdbcType="BIGINT"/><result column="role_code" property="roleCode" jdbcType="VARCHAR"/><result column="role_name" property="roleName" jdbcType="VARCHAR"/><result column="role_desc" property="roleDesc" jdbcType="VARCHAR"/><result column="create_user_id" property="createUserId" jdbcType="BIGINT"/><result column="modified_user_id" property="modifiedUserId" jdbcType="BIGINT"/><result column="gmt_create" property="gmtCreate" jdbcType="TIMESTAMP"/><result column="gmt_modified" property="gmtModified" jdbcType="TIMESTAMP"/><result column="is_deleted" property="isDeleted" jdbcType="TINYINT"/></resultMap><resultMap id="OrganizationMap" type="com.xx.springboot.business.system.domain.SysOrganizationDO"><id column="id" property="id" jdbcType="BIGINT"/><result column="organization_code" property="organizationCode" jdbcType="VARCHAR"/><result column="organization_name" property="organizationName" jdbcType="VARCHAR"/><result column="create_user_id" property="createUserId" jdbcType="BIGINT"/><result column="modified_user_id" property="modifiedUserId" jdbcType="BIGINT"/><result column="gmt_create" property="gmtCreate" jdbcType="TIMESTAMP"/><result column="gmt_modified" property="gmtModified" jdbcType="TIMESTAMP"/><result column="is_deleted" property="isDeleted" jdbcType="TINYINT"/></resultMap><!--子查询map,解决分页问题--><resultMap id="UserDtoMapSelect" type="com.xx.springboot.business.system.dto.UserDto"><id column="id" property="id" jdbcType="BIGINT"/><result column="open_id" property="openId" jdbcType="VARCHAR"/><result column="user_code" property="userCode" jdbcType="VARCHAR"/><result column="account" property="account" jdbcType="VARCHAR"/><result column="salt" property="salt" jdbcType="VARCHAR"/><result column="department_id" property="departmentId" jdbcType="VARCHAR"/><result column="department_name" property="departmentName" jdbcType="VARCHAR"/><result column="real_name" property="realName" jdbcType="VARCHAR"/><result column="age" property="age" jdbcType="BIGINT"/><result column="sex" property="sex" jdbcType="BIGINT"/><result column="phone" property="phone" jdbcType="VARCHAR"/><result column="phone" property="phone" jdbcType="VARCHAR"/><result column="id_card_num" property="idCardNum" jdbcType="VARCHAR"/><result column="email" property="email" jdbcType="VARCHAR"/><result column="address" property="address" jdbcType="VARCHAR"/><result column="create_user_id" property="createUserId" jdbcType="BIGINT"/><result column="modified_user_id" property="modifiedUserId" jdbcType="BIGINT"/><result column="gmt_create" property="gmtCreate" jdbcType="TIMESTAMP"/><result column="gmt_modified" property="gmtModified" jdbcType="TIMESTAMP"/><result column="is_deleted" property="isDeleted" jdbcType="TINYINT"/><collection property="roleDOList" column="id" select="getRoleListByUserId"/><collection property="organizationDOList" column="id" select="getOrganizationListByUserId"/></resultMap><select id="getAll" resultType="com.xx.springboot.business.system.domain.SysUserDO">select * from sys_user;</select><select id="getUserListPage" resultType="com.xx.springboot.business.system.domain.SysUserDO">select*from sys_userlimit #{start},#{size}</select><select id="getUserListPageNum" resultType="java.lang.Long">selectcount(*)from sys_user</select><select id="getUserByAccount" resultType="com.xx.springboot.business.system.domain.SysUserDO">select * from sys_user where account = #{account}</select><select id="selectEntityAndPage"parameterType="com.xx.springboot.business.system.domain.SysUserDO"resultType="com.xx.springboot.business.system.dto.UserDto">select *  from sys_user</select><select id="selectUserRole" resultType="com.xx.springboot.business.system.dto.UserRoleDto">select *  from sys_user u,sys_role_user ru,sys_role r where u.id = ru.user_id and r.id = ru.role_id</select><sql id="whereSql"><where><if test="1==1 ">su.is_deleted = 0</if><if test="organizationId != null and organizationId != '' ">and suo.organization_id = #{organizationId}</if><if test="roleId != null and roleId != '' ">and sru.role_id = #{roleId}</if><if test="account != null and account != '' ">and su.account = #{account}</if><if test="realName != null and realName != '' ">and su.real_name = #{realName}</if><if test="phone != null and phone != '' ">and su.phone = #{phone}</if><if test="email != null and email != '' ">and su.email = #{email}</if><if test="startTimestamp != null and startTimestamp != 0 ">and UNIX_TIMESTAMP(su.gmt_create) &gt;= #{startTimestamp}</if><if test="endTimestamp != null and endTimestamp != 0 ">and UNIX_TIMESTAMP(su.gmt_create ) &lt;= #{endTimestamp}</if></where></sql><select id="getUserDtoList1" resultMap="UserDtoMap">SELECTsu.id as id,su.open_id,su.user_code,su.account,su.salt,su.department_id,su.department_name,su.real_name,su.age,su.sex,su.phone,su.id_card_num,su.email,su.address,su.create_user_id,su.modified_user_id,su.gmt_create,su.gmt_modified,su.is_deleted,sr.id as sr_id,sr.role_code as sr_role_code,sr.role_name as sr_role_name,sr.role_desc as sr_role_desc,so.id as so_id,so.organization_name as so_organization_name,so.organization_code as so_organization_codeFROMsys_user suleft join sys_user_organization suo on suo.user_id = su.idleft join sys_organization so on so.id = suo.organization_idleft join sys_role_user sru on sru.user_id = su.idleft join sys_role sr on sr.id = sru.role_idWHERE su.id IN (select temp.id from(SELECT su.* FROM sys_user suLEFT JOIN sys_user_organization suo ON suo.user_id = su.idLEFT JOIN sys_role_user sru ON sru.user_id = su.id<include refid="whereSql"/>GROUP BY su.idlimit #{start},#{size}) as temp)</select><!-- 子查询方式 ,效率略低 --><select id="getUserDtoList" resultMap="UserDtoMapSelect">SELECTsu.id as id,su.open_id,su.user_code,su.account,su.salt,su.department_id,su.department_name,su.real_name,su.age,su.sex,su.phone,su.id_card_num,su.email,su.address,su.create_user_id,su.modified_user_id,su.gmt_create,su.gmt_modified,su.is_deletedFROMsys_user suleft join sys_user_organization suo on suo.user_id = su.idleft join sys_organization so on so.id = suo.organization_idleft join sys_role_user sru on sru.user_id = su.idleft join sys_role sr on sr.id = sru.role_id<include refid="whereSql"/>group by su.idlimit #{start},#{size}</select><select id="getUserDtoListNum" resultType="java.lang.Integer">selectcount(DISTINCT(su.id))FROMsys_user suleft join sys_user_organization suo on suo.user_id = su.idleft join sys_role_user sru on sru.user_id = su.id<include refid="whereSql"/></select><select id="getRoleListByUserId" resultType="com.xx.springboot.business.system.domain.SysRoleDO">SELECTsr.*FROMsys_role_user sruleft join sys_role sr on sr.id = sru.role_idWHEREsru.user_id = #{userId}</select><select id="getOrganizationListByUserId" resultType="com.xx.springboot.business.system.domain.SysOrganizationDO">SELECTso.*FROMsys_user_organization suoLEFT JOIN sys_organization so on so.id = suo.organization_idWHEREsuo.user_id = #{userId}</select>
</mapper>

mybatis collection 子查询,嵌套查询,解决分页问题相关推荐

  1. main方法 如何去掉http debug日志_在MyBatis中如何使用collection标签实现嵌套查询?...

    # 需求升级 在上篇博客<一对多的关系,在MyBatis中如何映射?>中,我们实现了需求:根据用户id查询用户信息的同时获取用户拥有的角色. 因为角色可以拥有多个权限,所以本篇博客我们升级 ...

  2. 2.4.3 Mybatis 高级查询, 复杂映射, 返回主键, 动态SQL if, set, foreach, 核心配置文件深入,plugins标签, 多表查询, 嵌套查询

    目录 Mybatis 复杂映射&配置文件深入 一 Mybatis高级查询 1.1 ResutlMap属性 1.2 多条件查询(三种) 1.3 模糊查询 二 Mybatis映射文件深入 2.1 ...

  3. MySQL 子查询 嵌套查询

    MySQL 子查询 嵌套查询 一.带IN关键字的子查询 二.带EXISTS关键字的查询 三.带ANY.SOME 关键字的子查询 四.带ALL 关键字的查询 自言自语 一.带IN关键字的子查询 使用IN ...

  4. sql 子查询 嵌套查询_SQL子查询– SQL中的嵌套查询

    sql 子查询 嵌套查询 In the real world, there are times when we need a particular set of data but we don't h ...

  5. mysql表子查询(嵌套查询)

    mysql表子查询(嵌套查询): 1.什么是子查询: 子查询是指嵌入在其它 sql 语句中的 select 语句,也叫嵌套查询 -- 如何显示与 SMITH 同一部门的所有员工? -- 1.先查出sm ...

  6. 连接查询--嵌套查询

    连接查询–嵌套查询 一.单层嵌套查询 嵌套查询分为相关嵌套查询.不相关嵌套查询.区分条件是分离之后是否可以单独查询. 不相关嵌套查询:由里向外查询,先执行子查询,得到的结果用来构造外部查询的条件.子查 ...

  7. 数据库SQL语言学习--上机练习2(连接查询 嵌套查询)(持续更新中)

    数据库SQL语言学习--上机练习2(连接查询 嵌套查询)(持续更新中) 上机练习2 1.              启动SQL Server 2008中的 SQL Server Management ...

  8. php redis 分页查询,redis如何解决分页查询

    我们都知道,通过缓存查询的结果,可以极大的提升系统的服务能力,以及降低底层服务或者是数据库的压力.对于有分页条件的缓存,我们也可以按照不同的分页条件来缓存多个key. 基于SortedSet的分页查询 ...

  9. SQL数据查询——嵌套查询

    嵌套查询 语法格式 带有IN谓词的子查询 IN谓词实现交运算 IN谓词实现差运算 带有比较运算符的子查询 带有ANY谓词的子查询 带有ALL谓词的子查询 相关子查询 引用子查询的值 不引用子查询的值( ...

最新文章

  1. FPGA(5)数码管静态显示与动态显示
  2. [分类整理IV]微软等100题系列V0.1版:字符串+数组面试题集锦
  3. [转贴]超过80%的80后大学生不知道自己将来要干什么
  4. 深度学习核心技术精讲100篇(五十四)-阿里文娱多模态视频分类算法中的特征改进
  5. 中国齿轮行业竞争分析与投资规模预测报告2021-2027年
  6. 地图API引发的设想
  7. 如何提高SSD的使用寿命
  8. CentOS 6.4利用xampp安装bugfree3
  9. python 函数定义位置_PYTHON--函数定义
  10. 毕设题目:Matlab优化求解
  11. [阿里云] 域名解析设置
  12. 【双轨】加权分红+三级分销+见点奖+级差源码系统 演示网站介绍
  13. java飞扬的小鸟,三国战纪,网络飞车游戏知识总结
  14. CSS之display用法
  15. 【分布式】分布式常见的十大坑,你了解几个?
  16. redis c++接口
  17. 百度ueditor粘贴word图片且图片文件自动上传功能
  18. [Pandas] DataFrame的columns属性
  19. switch调试软件+金手指
  20. 点燃我温暖你——李峋的爱心代码

热门文章

  1. java1.7 apk 签名_【keytool jarsigner工具的使用】Android 使用JDK1.7的工具 进行APK文件的签名,以及keystore文件的使用...
  2. dhcp、tftp及pxe简介
  3. 知名图床程序chevereto双十一半价促销,手把手教你如何搭建一个属于自己的无限存储图床
  4. 人为什么活着系列之十六:具体的人具体的环境具体分析
  5. Java开发工具有哪些
  6. APP开发后如何运营?
  7. 【HDU5984】Pocky(数学)
  8. 3蛋白wb_【Western-Blotting】WB核心理论:抗原抗体特异性反应
  9. LIN总线解析与UART模拟LIN从机实战
  10. 闲人闲谈PS之六——PS顾问升级树