1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="org.sang.mapper.MenuMapper">
  6. <resultMap id="BaseResultMap" type="org.sang.bean.Menu">
  7. <id column="id" property="id" jdbcType="INTEGER"/>
  8. <result column="url" property="url" jdbcType="VARCHAR"/>
  9. <result column="path" property="path" jdbcType="VARCHAR"/>
  10. <result column="component" property="component" javaType="java.lang.Object"/>
  11. <result column="name" property="name" jdbcType="VARCHAR"/>
  12. <result column="iconCls" property="iconCls" jdbcType="VARCHAR"/>
  13. <result column="keepAlive" property="keepAlive" jdbcType="BIT"/>
  14. <result column="parentId" property="parentId" jdbcType="INTEGER"/>
  15. <association property="meta" javaType="org.sang.bean.MenuMeta">
  16. <result column="keepAlive" property="keepAlive"/>
  17. <result column="requireAuth" property="requireAuth"/>
  18. </association>
  19. <collection property="roles" ofType="org.sang.bean.Role">
  20. <id column="rid" property="id"/>
  21. <result column="rname" property="name"/>
  22. <result column="rnamezh" property="nameZh"/>
  23. </collection>
  24. <collection property="children" ofType="org.sang.bean.Menu">
  25. <id column="id2" property="id"/>
  26. <result column="path2" property="path" jdbcType="VARCHAR"/>
  27. <result column="component2" property="component" jdbcType="VARCHAR"/>
  28. <result column="name2" property="name" jdbcType="VARCHAR"/>
  29. <result column="iconCls2" property="iconCls" jdbcType="VARCHAR"/>
  30. <association property="meta" javaType="org.sang.bean.MenuMeta">
  31. <result column="keepAlive2" property="keepAlive"/>
  32. <result column="requireAuth2" property="requireAuth"/>
  33. </association>
  34. <collection property="children" ofType="org.sang.bean.Menu">
  35. <id column="id3" property="id"/>
  36. <result column="name3" property="name" jdbcType="VARCHAR"/>
  37. </collection>
  38. </collection>
  39. </resultMap>
  40. <select id="getAllMenu" resultMap="BaseResultMap">
  41. 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
  42. </select>
  43. <select id="getMenusByHrId" parameterType="Long" resultMap="BaseResultMap">
  44. 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`
  45. </select>
  46. <select id="menuTree" resultMap="BaseResultMap">
  47. 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
  48. </select>
  49. <select id="getMenusByRid" resultType="Long">
  50. SELECT mid from menu_role WHERE rid=#{rid}
  51. </select>
  52. </mapper>

  

自定义ResultMap查询,这里的关联写法只能用于不分页的更多相关文章

  1. Spring Boot入门系列(十七)整合Mybatis,创建自定义mapper 实现多表关联查询!

    之前讲了Springboot整合Mybatis,介绍了如何自动生成pojo实体类.mapper类和对应的mapper.xml 文件,并实现最基本的增删改查功能.mybatis 插件自动生成的mappe ...

  2. Spring Security教程(二):自定义数据库查询

    Spring Security教程(二):自定义数据库查询   Spring Security自带的默认数据库存储用户和权限的数据,但是Spring Security默认提供的表结构太过简单了,其实就 ...

  3. Hibernate原生SQL查询多表关联,SQL语句要注意的问题

    Hibernate原生SQL查询多表关联,SQL语句要注意的问题 @for&ever 2009-9-4 系统环境: MySQL5.1 Hibernate3.3 有如下的假定: 实体类 Ques ...

  4. Hibernate自定义字段查询

    关于Hibernate自定义字段查询的方法,网上有很多,我这里就不详细写了,只把几个查询方法的注意事项说明一下. 废话少说, 进入正题: 假设有2个实体对象,Institution和User,结构与配 ...

  5. atitit. 集合groupby 的实现(2)---自定义linq查询--java .net php

    atitit.  集合groupby 的实现(2)---自定义linq查询--java .net php 实现方式有如下 1. Linq的实现原理流程(ati总结) 1 2. groupby  与 事 ...

  6. jeecg自定义datagrid查询

    为什么要写这篇文章? 我们了解,使用 jeecg 提供的 CriteriaQuery 查询方式,确实能满足绝大数的需求,但是往往有那么个比较复杂的情况,需要我们直接去写 sql,比如多表查询呀等等等等 ...

  7. SQL基础教程(第2版)第5章 复杂查询:5-3 关联子查询

    第5章 复杂查询:5-3 关联子查询 ● 关联子查询会在细分的组内进行比较时使用.● 关联子查询和GROUP BY子句一样,也可以对表中的数据进行切分.● 关联子查询的结合条件如果未出现在子查询之中就 ...

  8. webservice 测试窗体只能用于来自本地计算机的请求

    Question: WebService部署成站点之后,如果在本地测试webservice可以运行,在远程却显示“测试窗体只能用于来自本地计算机的请求”或者"The test form is ...

  9. 解决WebService 测试窗体只能用于来自本地计算机的请求

    问题: 今天上 午,WebService部署成站点之后,如果在本地测试webservice可以运行,在远程却显示“测试窗体只能用于来自本地计算机的请求”或 者"The test form i ...

随机推荐

  1. zeppelin 无法连接一个已有的standalone模式的spark集群

    SparkInterpreter.java  这个文件里面读取master的属性有些问题: 原来代码中"master"属性的获取的地方应该是错了.设置和读取这个属性的对象不是同一个 ...

  2. springboot非web项目

    使用CommandRunner @SpringBootApplication public class CrmApplication implements ApplicationRunner { @A ...

  3. ROC和AUC————摘在网络

    ROC曲线 对于0,1两类分类问题,一些分类器得到的结果往往不是0,1这样的标签,如神经网络,得到诸如0.5,0,8这样的分类结果.这时,我们人为取一个阈值,比如0.4,那么小于0.4的为0类,大于等 ...

  4. 综合开源框架之RxJava/RxAndroid

    * 一种帮助做异步的框架. 类似于 AsyncTask. 但其灵活性和扩展性远远强于前者. * 主页: https://github.com/ReactiveX/RxJava * 中文资料: * ht ...

  5. layui 常用确认框、提示框 demo

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...

  6. image-webpack-loader在mac或ubuntu报错

    解决办法安装libpng库,在github issue https://github.com/tcoopman/image-webpack-loader/issues/49可查看 mac: brew ...

  7. 看日志有没有 出现错误的字段 (如 crash ) 查找app闪退

    查看monkey的错误 在log里面查找 error  /  crashed /  Exception 1. ANR问题:在日志中搜索“ANR” 2.崩溃问题:在日志中搜索“Exception”  F ...

  8. django基础窗口类的使用

    django基础窗口form表单的运用 具体效果图如下: 首先确定表单中的数据集,先自己创建一个forms.py或者在原来的models.py中添加: 1代码如下 class ContactForm( ...

  9. Sqlserver实现故障转移 — AlwaysOn实现故障转移(4)

    目的:在已经加域的计算机上安装sqlserver2012,并配置系统级故障转移及数据库,实现AlwayOn. 域控的建立详见:https://www.cnblogs.com/xiaoerlang90/ ...

  10. 学习ansible笔记1

    ansible的特点: -- 模块化设计 -- 仅需要ssh和Python即可以使用 -- 无客户端 -- 功能强大,模块丰富 -- 上手容易门槛低 -- 基于python开发,做二次开发更容易 -- ...