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

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

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - MyBatis映射文件resultMap元素中使用多個association的方法

MyBatis映射文件resultMap元素中使用多個association的方法

2021-08-20 11:44Lw中 Java教程

這篇文章主要介紹了MyBatis映射文件resultMap元素中使用多個association的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

現在有一張訂單表t_stockorder,其擁有id、code、client_id、merchandise_id、merchandise_number、order_date、operator_id這些字段,其中client_id關聯t_client表中code字段,merchandise_id關聯t_merchandise表的code字段,operator_id關聯t_employee表的code字段。

現在要通過SQL語句將訂單表中t_stockorder的數據全部查詢出來,SQL語句如下所示:

?
1
2
3
4
5
6
7
8
9
10
11
select so.id, so.code, c.name cname, m.name mname,
    so.merchandise_number,
    so.order_date, e.name ename
    from
    inventory.t_stockorder so
    inner join
    inventory.t_client c on c.code = so.client_id
    inner join
    inventory.t_merchandise m on m.code = so.merchandise_id
    inner join
    inventory.t_employee e on e.code = so.operator_id

現在要在mapper映射文件中添加動態Sql語句,一般情況下映射文件中的resultMap元素中只可以有一個association,那如何添加多個association到resultMap中呢?正確代碼如下圖所示:

?
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<resultMap id="StockorderMap" type="com.lwz.entity.Stockorder">
    <id property="id" column="id" />
    <result property="code" column="code" />
    <result property="merchandiseNumber" column="merchandise_number" />
    <result property="orderDate" column="order_date" />
    <association property="client" javaType="Client" resultMap="ClientResultMap"></association>
    <association property="merchandise" javaType="Merchandise" resultMap="MerchandiseResultMap"></association>
    <association property="employee" javaType="Employee" resultMap="EmployeeResultMap"></association>
  </resultMap>
  <resultMap id="ClientResultMap" type="com.lwz.entity.Client">
    <id property="code" column="code" />
    <result property="name" column="cname" />
  </resultMap>
  <resultMap id="MerchandiseResultMap" type="com.lwz.entity.Merchandise">
    <id property="code" column="code" />
    <result property="name" column="mname" />
  </resultMap>
  <resultMap id="EmployeeResultMap" type="com.lwz.entity.Employee">
    <id property="code" column="code" />
    <result property="name" column="ename" />
  </resultMap>
 
  <!--通過實體作為篩選條件查詢-->
  <select id="queryAll" resultMap="StockorderMap">
    select so.id, so.code, c.name cname, m.name mname,
    so.merchandise_number,
    so.order_date, e.name ename
    from
    inventory.t_stockorder so
    inner join
    inventory.t_client c on c.code = so.client_id
    inner join
    inventory.t_merchandise m on m.code = so.merchandise_id
    inner join
    inventory.t_employee e on e.code = so.operator_id
    <where>
      <if test="id != null">
        and id = #{id}
      </if>
      <if test="code != null and code != ''">
        and so.code = #[code]
      </if>
      <if test="client != null">
        and client_id = #{client.code}
      </if>
      <if test="merchandise != null">
        and merchandise_id = #{merchandise.code}
      </if>
      <if test="merchandiseNumber != null">
        and merchandise_number = #{merchandiseNumber}
      </if>
      <if test="orderDate != null">
        and order_date = #{orderDate}
      </if>
      <if test="employee != null">
        and operator_id = #{employee.code}
      </if>
    </where>
  </select>

resultMap中association的各個屬性的含義:

  • property:映射實體類的字段或屬性。
  • colum:數據庫的列名或者列標簽別名。
  • javaTyp:完整java類名或別名。
  • jdbcType支持的JDBC類型列表列出的JDBC類型。這個屬性只在insert,update或delete的時候針對允許空的列有用。
  • resultMap: 一個可以映射聯合嵌套結果集到一個適合的對象視圖上的ResultMap。這是一個替代的方式去調用另一個select語句。

到此這篇關于MyBatis映射文件resultMap元素中使用多個association的方法的文章就介紹到這了,更多相關MyBatis 多個association內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家! 

原文鏈接:https://blog.csdn.net/weixin_43894879/article/details/106770531

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 高清毛片一区二区三区 | 国产综合色在线视频区色吧图片 | 9久热这里只有精品免费 | 二次元美女内裤凹陷太深 | 国产精品俺来也在线观看了 | 日韩在线免费看 | tkvk视频| 亚洲天堂激情 | 波多野结衣被绝伦强在线观看 | 按摩院已婚妇女中文字幕 | 国产精品合集一区二区 | 国产精品区一区二区免费 | 国产在线看片网站 | 午夜视频一区二区三区 | 娇妻与老头绿文小说系列 | 色噜噜亚洲男人的天堂www | 美女被视频网站 | 国产日韩精品一区二区三区 | 色啪久久婷婷综合激情 | 四虎1515hh.com | 四虎成人免费观看在线网址 | 扒开黑女人p大荫蒂老女人 扒开大腿狠狠挺进视频 | 国产亚洲精品激情一区二区三区 | 7777色鬼xxxx欧美色夫 | heyzo在线观看 | 3d动漫被吸乳羞羞 | 日本老熟老太hd | 亚洲视频在线免费 | chinesespanking调教 | 久9青青cao精品视频在线 | 亚洲无线一二三区2021 | 欧美国产日本高清不卡 | www射com| 天堂激情网 | 国产成人 免费观看 | 日韩视频一区 | 日本一区二区不卡久久入口 | 日韩毛片基地一区二区三区 | pregnant欧美孕交xxx | 91av免费在线观看 | 日本mv精品中文字幕 |