一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

Mysql|Sql Server|Oracle|Redis|MongoDB|PostgreSQL|Sqlite|DB2|mariadb|Access|數據庫技術|

服務器之家 - 數據庫 - Sql Server - mybatis collection 多條件查詢的實現方法

mybatis collection 多條件查詢的實現方法

2020-05-23 16:42焦點 Sql Server

這篇文章主要介紹了mybatis collection 多條件查詢的實現方法的相關資料,希望通過本文能幫助到大家,需要的朋友可以參考下

mybatis collection 多條件查詢的實現方法

前言:

業務需要通過mybatis 查詢返回嵌套集合,嫌多次查詢太麻煩,用自帶的高級查詢解決問題,下邊是代碼,已測試通過。

說下自己的理解,就是一個主查詢結果集里面嵌套了子查詢的結果集,可以是多個子查詢,每個子查詢的條件從主查詢結果集中獲取,返回值各自定義。collection 標簽的property是主查詢里面集合的名字,如果有多個就再寫個collection,column是子查詢參數,單參數直接寫主查詢結合返回結果,例如直接寫上user_id,要是數據庫的字段,多條件就封裝下,例如{userId=user_id,theme=theme},然后子查詢的parameterType寫"java.util.Map",多條件查詢好像只有mybatis3.0以后才有,看網上資料說的,沒驗證過,ofType是集合里的對象,select是對應下面的語句

實現代碼:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<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,

這個屬性,下面是返回值結構截圖

mybatis collection 多條件查詢的實現方法

如有疑問請留言或者到本站社區交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

原文鏈接:http://blog.csdn.net/di315362886/article/details/60144410

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 精品国语对白精品自拍视 | 操破苍穹在线 | 亚洲国产精品久久无套麻豆 | 日韩视频在线精品视频免费观看 | 91精品综合久久久久m3u8 | 成人日批视频 | 国产一区二区三区久久精品 | 女教师雪白老汉 | 把女的下面扒开添视频 | 国产成人综合亚洲亚洲欧美 | 欧美bbb人妖 | 男人的天堂在线观看视频不卡 | 成年人在线免费观看视频网站 | 欧美成人tv在线观看免费 | 99久久精品国产综合一区 | 波多野结衣教师未删减版 | 丰满的闺蜜2中文字幕 | 日本国产最新一区二区三区 | japonensis中国东北老人 | 日韩欧美一区二区三区免费看 | 亚欧日韩 | yy6080欧美三级理论 | 99爱免费| 爸爸的宝贝小说全文在线阅读 | 国产一区二区在线免费观看 | 国产精品边做边接电话在线观看 | 精品久久久久久久久免费影院 | 久久久无码精品亚洲A片猫咪 | 欧美伊人久久久久久久久影院 | 天天躁夜夜躁很很躁 | 新新电影理论中文字幕 | 亚洲第一网站免费视频 | 999国产| 免费观看在线永久免费xx视频 | 92福利网 | 亚洲精品m在线观看 | 四虎影院网址大全 | 东方影库四虎 | 久久免费看少妇高潮A片特爽 | 国产特级毛片aaaaaa | 精新精新国产自在现 |