欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

MsSql

當(dāng)前位置:主頁 > 數(shù)據(jù)庫 > MsSql >

mybatis collection 多條件查詢的實現(xiàn)方法

來源:本站原創(chuàng)|時間:2020-01-10|欄目:MsSql|點擊: 次

mybatis collection 多條件查詢的實現(xiàn)方法

前言:

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

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

實現(xiàn)代碼:

<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,

這個屬性,下面是返回值結(jié)構(gòu)截圖

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

上一篇:SQL Server在AlwaysOn中使用內(nèi)存表的“踩坑”記錄

欄    目:MsSql

下一篇:詳解SQL Server數(shù)據(jù)庫狀態(tài)和文件狀態(tài)

本文標(biāo)題:mybatis collection 多條件查詢的實現(xiàn)方法

本文地址:http://mengdiqiu.com.cn/a1/MsSql/10428.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有