mybatis中的collection标签使用说明

2024-06-10 19:32

本文主要是介绍mybatis中的collection标签使用说明,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >  
  3. <mapper namespace="SHIRO_SpecSql" >  
  4.       
  5.     <!-- 获得这个用户所有的菜单权限 -->  
  6.     <select id="searchSingleUserMenuAuthorities" parameterType="java.lang.String" resultMap="OneMenuAuthority">  
  7.         select   
  8.         name name,  
  9.         ht_authority_id htAuthorityId,  
  10.         (select ${uid} from dual ) currentUserId  
  11.         from ht_authority   
  12.         where pid = 0  
  13.     </select>  
  14.     <resultMap type="com.sailod.shiro.dto.HtAuthorityMenuDTO" id="OneMenuAuthority">  
  15.         <id property="htAuthorityId" column="htAuthorityId" javaType="java.lang.Long" />  
  16.         <result property="name" column="name" javaType="java.lang.String" />  
  17.         <result property="currentUserId" column="currentUserId" javaType="java.lang.Long" />  
  18.         <collection property="htAuthorityDTO"  ofType="com.sailod.shiro.dto.HtAuthorityDTO"  
  19.          select="selectAuthority" column="{htAuthorityId2 = htAuthorityId ,currentUserId2 = currentUserId}"   >  
  20.          </collection>  
  21.     </resultMap>  
  22.     <select id="selectAuthority" parameterType="java.util.HashMap" resultType="com.sailod.shiro.dto.HtAuthorityDTO" resultMap="OneAuthority"  >  
  23.         select ha.name name,  
  24.         ha.url url ,  
  25.         ha.ht_authority_id htauthorityid,  
  26.         ha.pid pid,  
  27.         ha.type type,  
  28.         ha.permission permission,  
  29.         hua.ht_user_id currUserId  
  30.         from ht_authority ha  
  31.         left join ht_user_authority hua on hua.ht_authority_id = ha.ht_authority_id   
  32.         where ha.pid = ${htAuthorityId2}  
  33.         and ha.type = 'menu'   
  34.         and hua.ht_user_id = ${currentUserId2}   
  35.     </select>  
  36.     <resultMap type="com.sailod.shiro.dto.HtAuthorityDTO" id="OneAuthority" >  
  37.         <id property="pid" column="pid" javaType="java.lang.Long" />  
  38.         <result property="name" column="name"  javaType="java.lang.String"/>  
  39.         <result property="url" column="url" javaType="java.lang.String"/>  
  40.         <result property="type" column="type" javaType="java.lang.String"/>  
  41.         <result property="permission" column="permission" javaType="java.lang.String"/>  
  42.         <result property="htAuthorityId" column="htauthorityid" javaType="java.lang.Long"/>  
  43.         <result property="currUserId" column="currUserId" javaType="java.lang.Long" />  
  44.     </resultMap>  
  45. </mapper>  


<resultMap>其实就是返回类型为其引用的id的   标签所定义的。

<collection> 往这个标签定义的 ‘类’ 的 list 属性中设置值, 如何设置值? 还要根据其 select="selectAuthority"  , 把值查询出来。

 

 

 

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. package com.sailod.shiro.dto;  
  2.   
  3. import java.util.List;  
  4.   
  5. /** 
  6.  * 查询菜单用到dto 
  7.  *  
  8.  * 
  9.  */  
  10. public class HtAuthorityMenuDTO {  
  11.       
  12.   
  13.     private String name;  
  14.       
  15.     private Long htAuthorityId;  
  16.       
  17.     private Long currentUserId;  
  18.       
  19.     private List<HtAuthorityDTO> htAuthorityDTO;  
  20.   
  21.     public Long getHtAuthorityId() {  
  22.         return htAuthorityId;  
  23.     }  
  24.   
  25.     public void setHtAuthorityId(Long htAuthorityId) {  
  26.         this.htAuthorityId = htAuthorityId;  
  27.     }  
  28.   
  29.       
  30.   
  31.     public String getName() {  
  32.         return name;  
  33.     }  
  34.   
  35.     public void setName(String name) {  
  36.         this.name = name;  
  37.     }  
  38.   
  39.     public List<HtAuthorityDTO> getHtAuthorityDTO() {  
  40.         return htAuthorityDTO;  
  41.     }  
  42.   
  43.     public void setHtAuthorityDTO(List<HtAuthorityDTO> htAuthorityDTO) {  
  44.         this.htAuthorityDTO = htAuthorityDTO;  
  45.     }  
  46.   
  47.     public Long getCurrentUserId() {  
  48.         return currentUserId;  
  49.     }  
  50.   
  51.     public void setCurrentUserId(Long currentUserId) {  
  52.         this.currentUserId = currentUserId;  
  53.     }  
  54.       
  55.       
  56. }  


 

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. package com.sailod.shiro.dto;  
  2.   
  3. /** 
  4.  * 查询菜单用到dto 
  5.  *  
  6.  * 
  7.  */  
  8. public class HtAuthorityDTO {  
  9.       
  10.     //这个权限的主键  
  11.     private Long htAuthorityId;  
  12.     //父菜单的主键  
  13.     private Long pid;  
  14.       
  15.     private String name;  
  16.       
  17.     private String url;  
  18.     //类型  
  19.     private String type;  
  20.       
  21.     private String permission;  
  22.       
  23.     private Long currUserId;  
  24.       
  25.       
  26.     public String getName() {  
  27.         return name;  
  28.     }  
  29.   
  30.     public void setName(String name) {  
  31.         this.name = name;  
  32.     }  
  33.   
  34.     public String getUrl() {  
  35.         return url;  
  36.     }  
  37.   
  38.     public void setUrl(String url) {  
  39.         this.url = url;  
  40.     }  
  41.   
  42.     public Long getHtAuthorityId() {  
  43.         return htAuthorityId;  
  44.     }  
  45.   
  46.     public void setHtAuthorityId(Long htAuthorityId) {  
  47.         this.htAuthorityId = htAuthorityId;  
  48.     }  
  49.   
  50.     public Long getPid() {  
  51.         return pid;  
  52.     }  
  53.   
  54.     public void setPid(Long pid) {  
  55.         this.pid = pid;  
  56.     }  
  57.   
  58.     public String getType() {  
  59.         return type;  
  60.     }  
  61.   
  62.     public void setType(String type) {  
  63.         this.type = type;  
  64.     }  
  65.   
  66.     public String getPermission() {  
  67.         return permission;  
  68.     }  
  69.   
  70.     public void setPermission(String permission) {  
  71.         this.permission = permission;  
  72.     }  
  73.   
  74.     public Long getCurrUserId() {  
  75.         return currUserId;  
  76.     }  
  77.   
  78.     public void setCurrUserId(Long currUserId) {  
  79.         this.currUserId = currUserId;  
  80.     }  
  81.   
  82.       
  83.       
  84.       
  85. }  


 

 

 

 低效率 collection:

 

 

 

 

高效率collection,  

1 查询用联合查询

2<collection 里面不写column  

这篇关于mybatis中的collection标签使用说明的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1049057

相关文章

C语言中联合体union的使用

本文编辑整理自: http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=179471 一、前言 “联合体”(union)与“结构体”(struct)有一些相似之处。但两者有本质上的不同。在结构体中,各成员有各自的内存空间, 一个结构变量的总长度是各成员长度之和。而在“联合”中,各成员共享一段内存空间, 一个联合变量

Tolua使用笔记(上)

目录   1.准备工作 2.运行例子 01.HelloWorld:在C#中,创建和销毁Lua虚拟机 和 简单调用。 02.ScriptsFromFile:在C#中,对一个lua文件的执行调用 03.CallLuaFunction:在C#中,对lua函数的操作 04.AccessingLuaVariables:在C#中,对lua变量的操作 05.LuaCoroutine:在Lua中,

Vim使用基础篇

本文内容大部分来自 vimtutor,自带的教程的总结。在终端输入vimtutor 即可进入教程。 先总结一下,然后再分别介绍正常模式,插入模式,和可视模式三种模式下的命令。 目录 看完以后的汇总 1.正常模式(Normal模式) 1.移动光标 2.删除 3.【:】输入符 4.撤销 5.替换 6.重复命令【. ; ,】 7.复制粘贴 8.缩进 2.插入模式 INSERT

持久层 技术选型如何决策?JPA,Hibernate,ibatis(mybatis)

转自:http://t.51jdy.cn/thread-259-1-1.html 持久层 是一个项目 后台 最重要的部分。他直接 决定了 数据读写的性能,业务编写的复杂度,数据结构(对象结构)等问题。 因此 架构师在考虑 使用那个持久层框架的时候 要考虑清楚。 选择的 标准: 1,项目的场景。 2,团队的技能掌握情况。 3,开发周期(开发效率)。 传统的 业务系统,通常业

Java面试题:通过实例说明内连接、左外连接和右外连接的区别

在 SQL 中,连接(JOIN)用于在多个表之间组合行。最常用的连接类型是内连接(INNER JOIN)、左外连接(LEFT OUTER JOIN)和右外连接(RIGHT OUTER JOIN)。它们的主要区别在于它们如何处理表之间的匹配和不匹配行。下面是每种连接的详细说明和示例。 表示例 假设有两个表:Customers 和 Orders。 Customers CustomerIDCus

Lipowerline5.0 雷达电力应用软件下载使用

1.配网数据处理分析 针对配网线路点云数据,优化了分类算法,支持杆塔、导线、交跨线、建筑物、地面点和其他线路的自动分类;一键生成危险点报告和交跨报告;还能生成点云数据采集航线和自主巡检航线。 获取软件安装包联系邮箱:2895356150@qq.com,资源源于网络,本介绍用于学习使用,如有侵权请您联系删除! 2.新增快速版,简洁易上手 支持快速版和专业版切换使用,快速版界面简洁,保留主

如何免费的去使用connectedpapers?

免费使用connectedpapers 1. 打开谷歌浏览器2. 按住ctrl+shift+N,进入无痕模式3. 不需要登录(也就是访客模式)4. 两次用完,关闭无痕模式(继续重复步骤 2 - 4) 1. 打开谷歌浏览器 2. 按住ctrl+shift+N,进入无痕模式 输入网址:https://www.connectedpapers.com/ 3. 不需要登录(也就是

Toolbar+DrawerLayout使用详情结合网络各大神

最近也想搞下toolbar+drawerlayout的使用。结合网络上各大神的杰作,我把大部分的内容效果都完成了遍。现在记录下各个功能效果的实现以及一些细节注意点。 这图弹出两个菜单内容都是仿QQ界面的选项。左边一个是drawerlayout的弹窗。右边是toolbar的popup弹窗。 开始实现步骤详情: 1.创建toolbar布局跟drawerlayout布局 <?xml vers

C#中,decimal类型使用

在Microsoft SQL Server中numeric类型,在C#中使用的时候,需要用decimal类型与其对应,不能使用int等类型。 SQL:numeric C#:decimal

探索Elastic Search:强大的开源搜索引擎,详解及使用

🎬 鸽芷咕:个人主页  🔥 个人专栏: 《C++干货基地》《粉丝福利》 ⛺️生活的理想,就是为了理想的生活! 引入 全文搜索属于最常见的需求,开源的 Elasticsearch (以下简称 Elastic)是目前全文搜索引擎的首选,相信大家多多少少的都听说过它。它可以快速地储存、搜索和分析海量数据。就连维基百科、Stack Overflow、