婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > 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 ListUserMessageDetail> userMessageDetailList,

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

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

您可能感興趣的文章:
  • Mybatis中Collection集合標簽的使用詳解
  • 詳解mybatis foreach collection示例
  • 解決mybatis 中collection嵌套collection引發的bug
  • Mybatis collection查詢集合屬性報錯的解決方案

標簽:宿州 來賓 威海 天水 銅仁 防疫戰設 益陽 七臺河

巨人網絡通訊聲明:本文標題《mybatis collection 多條件查詢的實現方法》,本文關鍵詞  mybatis,collection,多,條件,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《mybatis collection 多條件查詢的實現方法》相關的同類信息!
  • 本頁收集關于mybatis collection 多條件查詢的實現方法的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 丘北县| 宁波市| 泌阳县| 绩溪县| 宾阳县| 九台市| 新乐市| 土默特左旗| 江门市| 北安市| 峨眉山市| 碌曲县| 连州市| 金山区| 察哈| 锡林郭勒盟| 南澳县| 泸定县| 加查县| 杂多县| 景东| 鲜城| 斗六市| 遵义县| 泸定县| 沧州市| 延长县| 津市市| 泰兴市| 保亭| 绥德县| 衡水市| 澳门| 乌兰县| 合水县| 永福县| 太仆寺旗| 格尔木市| 博爱县| 彭阳县| 霸州市|