没有合适的资源?快使用搜索试试~ 我知道了~
首页mybatis collection 多条件查询的实现方法
mybatis collection 多条件查询的实现方法
6 下载量 166 浏览量
更新于2023-03-16
收藏 154KB PDF 举报
主要介绍了mybatis collection 多条件查询的实现方法的相关资料,希望通过本文能帮助到大家,需要的朋友可以参考下
资源详情
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/12826295/bg1.jpg)
mybatis collection 多条件查询的实现方法多条件查询的实现方法
主要介绍了mybatis collection 多条件查询的实现方法的相关资料,希望通过本文能帮助到大家,需要的朋友可以参考下
mybatis collection 多条件查询的实现方法多条件查询的实现方法
前言:前言:
业务需要通过mybatis 查询返回嵌套集合,嫌多次查询太麻烦,用自带的高级查询解决问题,下边是代码,已测试通过。
说下自己的理解,就是一个主查询结果集里面嵌套了子查询的结果集,可以是多个子查询,每个子查询的条件从主查询结果集中获取,返回值各自定义。collection 标签的property是主
查询里面集合的名字,如果有多个就再写个collection,column是子查询参数,单参数直接写主查询结合返回结果,例如直接写上user_id,要是数据库的字段,多条件就封装下,例如
{userId=user_id,theme=theme},然后子查询的parameterType写"java.util.Map",多条件查询好像只有mybatis3.0以后才有,看网上资料说的,没验证过,ofType是集合里的对
象,select是对应下面的语句
实现代码:
<resultMap id="BaseResultMap" type="web.model.UserMessage" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="user_id" property="userId" jdbcType="INTEGER" />
<result column="theme" property="theme" jdbcType="VARCHAR" />
<result column="status" property="status" jdbcType="INTEGER" />
<result column="theme_time" property="themeTime" jdbcType="TIMESTAMP" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
<result column="yn" property="yn" jdbcType="INTEGER" />
</resultMap>
<resultMap id="BaseVoResultMap" type="web.model.vo.UserMessageVo" extends="BaseResultMap">
<collection property="userMessageDetailList" column="{userId=user_id,theme=theme}" javaType="java.util.ArrayList" ofType="web.model.UserMessageDetail" select="selectUserMessageDetailById"/>
</resultMap>
<resultMap id="BaseDetailResultMap" type="web.model.UserMessageDetail" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="user_message_id" property="userMessageId" jdbcType="INTEGER" />
<result column="sponsor_id" property="sponsorId" jdbcType="INTEGER" />
<result column="user_id" property="userId" jdbcType="INTEGER" />
<result column="user_type" property="userType" jdbcType="INTEGER" />
<result column="provider_id" property="providerId" jdbcType="INTEGER" />
<result column="message" property="message" jdbcType="VARCHAR" />
<result column="status" property="status" jdbcType="INTEGER" />
<result column="message_time" property="messageTime" jdbcType="TIMESTAMP" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
<result column="yn" property="yn" jdbcType="INTEGER" />
</resultMap>
<select id="selectUserMessageById" resultMap="BaseVoResultMap" parameterType="java.lang.Integer">
select * from user_message where user_id = #{userId,jdbcType=INTEGER}
</select>
<select id="selectUserMessageDetailById" resultMap="BaseDetailResultMap" parameterType="java.util.Map">
select * from user_message_detail where user_id = #{userId,jdbcType=INTEGER} and message = #{theme,jdbcType=VARCHAR}
</select>
selectUserMessageById,这个是主查询,VO只多了个 private List<UserMessageDetail> userMessageDetailList,
这个属性,下面是返回值结构截图
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://profile-avatar.csdnimg.cn/default.jpg!1)
weixin_38591011
- 粉丝: 4
- 资源: 919
上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![](https://csdnimg.cn/release/wenkucmsfe/public/img/voice.245cc511.png)
会员权益专享
最新资源
- 基于单片机的瓦斯监控系统硬件设计.doc
- 基于单片机的流量检测系统的设计_机电一体化毕业设计.doc
- 基于单片机的继电器设计.doc
- 基于单片机的湿度计设计.doc
- 基于单片机的流量控制系统设计.doc
- 基于单片机的火灾自动报警系统毕业设计.docx
- 基于单片机的铁路道口报警系统设计毕业设计.doc
- 基于单片机的铁路道口报警研究与设计.doc
- 基于单片机的流水灯设计.doc
- 基于单片机的时钟系统设计.doc
- 基于单片机的录音器的设计.doc
- 基于单片机的万能铣床设计设计.doc
- 基于单片机的简易安防声光报警器设计.doc
- 基于单片机的脉搏测量器设计.doc
- 基于单片机的家用防盗报警系统设计.doc
- 基于单片机的简易电子钟设计.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![](https://csdnimg.cn/release/wenkucmsfe/public/img/green-success.6a4acb44.png)