记录下mybatis的集合查询中碰到的问题
MyBatis ofType和javaType区别
mybatis 关联查询 resultMap 同名冲突
使用mybatis的resultMap进行复杂查询
mybatis <collection>标签 类型为string时无法获取重复数据错误
使用resultMap进行一对多关联查询的方式有两种:
方法 1、 使用左连接查询所有关联数据
1. <resultMap id="peopleResultMap" type="People">
2. <id property="id" column="id" />
3. <result property="name" column="name" />
4. <collection property="qqs" ofType="string" javaType="list">
5. <result column="qq" />
6. </collection>
7. </resultMap>
8.
9. <select id="selectPeopleById" resultMap="peopleResultMap">
10. select p.*,pq.qq from
11. people p left join people_qq pq on p.id = pq.people_id
12. where p.id = #{id}
13. </select>
如上面,左连接关联查询出qq表的qq字段,然后将qq通过resultMap的集合类放到这个List<String> qqs这个属性字段中。
优点:查询数据只需要查询一次就可以了。
缺点:因为左连接查询,people表一对多qq表,会查询出重复的id数据行。这样就无法使用到数据库自带的分页函数。
select p.*,pq.qq from
people p left join people_qq pq on p.id = pq.people_id
where p.id = #{id}
上面这个sql查询出来的数据格式
如下:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXAAAADFCAYAAABNaalNAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAACQ9SURBVHhe7Z27kizHYabnkdaQcTAvIm8N6sQ8w9Jej4KCs7ZegNYqIOMYayhiTZnLEA8XmHPBlSBBkOIywAvktCqruroys76sysy/CofE/n/EF2RXVl7R9U12DtBzd3Ecx3H+KnMT+KtXry4f/vpbYw4nvLccZyt+j/TFAjen44fT2YvfI32xwM3p+OF09uL3SF8scHM6fjidvfg90hcL3JyOH05nL36P9IUF/q9/f/kvd88uP/zX9EG88ZO/u9z9zd9f/heVGZPhh9PZi98jfbHAzen44XT24vdIX/qOUCxw04AfTmcvfo/0xQI3p+OH09mL3yN92ThC+bvLP94ewg8uf3t3d7mLscBNJeuH88XlIX8/vffjy9O1dL/c+b7FAu9LhcAnef/tT5YH8h//6/BAWeCmkvThn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AElFTkSuQmCC" alt="" />
方法 2 使用子查询的方式查询
1. <resultMap id="peopleResultMap" type="People">
2. <id property="id" column="id" />
3. <result property="name" column="name" />
4. <collection property="qqs" ofType="string" javaType="list">
5. <result column="qq" />
6. </collection>
7. </resultMap>
8.
9. <select id="selectPeopleById" resultMap="peopleResultMap">
10. select p.*,pq.qq from
11. people p left join people_qq pq on p.id = pq.people_id
12. where p.id = #{id}
13. </select>
子查询,就是在集合列表中调用另一个查询,进行数据赋值。
优点:可以使用数据库自带的分页函数
缺点:查询数据需要多次调用子查询进行集合字段数据查询。如果是大数据量查询,将会需要多次调用子查询sql。
mybatis默认使用懒加载的方式进行集合的子查询。存在问题。
可以查看下面这篇文章:mybatis问题解决
Springmvc+mybatis,mybatis配置延迟加载时,json序列化异常
https://ask.csdn.net/questions/344738?sort=comments_count
实体类有一个属性是其它实体类的类型,mybatis默认使用了 延迟加载,导致在处理这个类的时候某些属性不能被序列化,因此造成了上述原因
https://www.oschina.net/question/2312022_2232071
最近做项目时,使用了mybatis级联查询,配置了懒加载模式,结果通过springMvc返回json时报的错。报错如下:
https://blog.csdn.net/qq_33548914/article/details/79991280
- 使用MyBatis的resultMap高级查询时常用的方式总结
以下内容已经通过楼主测试, 从pd设计数据库到测试完成, 之前楼主也没有过Mybatis 使用resultMap觉得有点乱,最近抽出时间总结了一下也算对MyBatis的resultMap进行一次系统的 ...
- mybatis由浅入深day02_2一对一查询_2.3方法二:resultMap_resultType和resultMap实现一对一查询小结
2.3 方法二:resultMap 使用resultMap,定义专门的resultMap用于映射一对一查询结果. 2.3.1 sql语句 同resultType实现的sql SELECT orders ...
- 好947 Mybatis 配置resultMap 带參数查询Map 注意selectOne数据库返回结果一条数据库 否则会报错
//TMD 写几个demo 还有大站採集 <a target=_blank href="http://hao947.com/" target="_blank&quo ...
- Mybatis的ResultMap与limit分页查询
ResultMap主要解决的是:属性名和字段不一致 如果在pojo中设置的是一个名字,在数据库上又是另一个名字,那么查询出来的结果或者其他操作的结果就为null. //在pojo中 private S ...
- Mybatis的ResultMap的使用
本篇文章通过一个实际工作中遇到的例子开始吧: 工程使用Spring+Mybatis+Mysql开发.具体的业务逻辑很重,对象之间一层一层的嵌套.和数据库表对应的是大量的model类,而和前端交互的是V ...
- mybatis系列-11-一对多查询
11.1 需求 查询订单及订单明细的信息. 11.2 sql语句 确定主查询表:订单表 确定关联查询表:订单明细表 在一对一查询基础上添加订单明细表关联即可. SELECT order ...
- mybatis系列-10-一对一查询
10.1 需求 查询订单信息,关联查询创建订单的用户信息 10.2 resultType 10.2.1 sql语句 确定查询的主表:订单表 确定查询的关联表:用户表 关联查询 ...
- Mybatis的ResultMap的使用(转)
本篇文章通过一个实际工作中遇到的例子开始吧: 工程使用Spring+Mybatis+Mysql开发.具体的业务逻辑很重,对象之间一层一层的嵌套.和数据库表对应的是大量的model类,而和前端交互的是V ...
- Mybatis之ResultMap一个简短的引论,关联对象
基础部分能够查看我的还有一篇博客http://blog.csdn.net/elim168/article/details/40622491 MyBatis中在查询进行select映射的时候.返回类型能 ...
随机推荐
- c# json数据解析——将字符串json格式数据转换成对象或实体类
网络中数据传输经常是xml或者json,现在做的一个项目之前调其他系统接口都是返回的xml格式,刚刚遇到一个返回json格式数据的接口,通过例子由易到难总结一下处理过程,希望能帮到和我一样开始不会的朋 ...
- solr query没有反应,地址报错查询的地址error
随便修改了一下angular.js,保存,再修改,就可以查询了 问题应该是对文件没有操作权限.感觉solr在部署时对文件的授权还是很重要的
- python panda读写内存溢出:MemoryError
pandas中read_xxx的块读取功能 pandas设计时应该是早就考虑到了这些可能存在的问题,所以在read功能中设计了块读取的功能,也就是不会一次性把所有的数据都放到内存中来,而是分块读到内存 ...
- linux 信号量
https://www.jianshu.com/p/6e72ff770244 无名信号量 #include <time.h> #include <stdio.h> #inclu ...
- How to find First Non-Repeated Character from String
You need to write a function, which will accept a String and return first non-repeated character, fo ...
- C++指针图解
- 【题解】间隔排列-C++
题目Description小Q是班长.在校运动会上,小Q班要进行队列表演.小Q要选出2*N名同学编队,每人都被编上一个号,每一个从1到N的自然数都被某2名同学佩戴,现在要求将他们排成一列,使两个编号为 ...
- ckeditor粘贴word图片自动上传功能
由于工作需要必须将word文档内容粘贴到编辑器中使用 但发现word中的图片粘贴后变成了file:///xxxx.jpg这种内容,如果上传到服务器后其他人也访问不了,网上找了很多编辑器发现没有一个能直 ...
- 安装更新npm和nodejs
1.安装npm sudo apt-get install npm 2.升级npm sudo npm install npm@latest -g 3.安装用于安装nodejs的模块n sudo npm ...
- anaconda安装和配置和基本使用
conda是个商业化公司,所以没有授权不能随便建立其镜像.虽说说的是发邮件询问基本上就能够拿到授权,然而现实是国内的各大开源镜像站都拿不到. 这个事情最近有进展了. 清华大学的镜像源已经拿到授权了 ( ...