欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

現(xiàn)在要通過SQL語句將訂單表中t_stockorder的數(shù)據(jù)全部查詢出來,SQL語句如下所示:

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

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

<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:映射實體類的字段或?qū)傩浴?/li>
  • colum:數(shù)據(jù)庫的列名或者列標簽別名。
  • javaTyp:完整java類名或別名。
  • jdbcType支持的JDBC類型列表列出的JDBC類型。這個屬性只在insert,update或delete的時候針對允許空的列有用。
  • resultMap: 一個可以映射聯(lián)合嵌套結(jié)果集到一個適合的對象視圖上的ResultMap。這是一個替代的方式去調(diào)用另一個select語句。

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

相關文章

  • springboot實現(xiàn)獲取客戶端IP地址的示例代碼

    springboot實現(xiàn)獲取客戶端IP地址的示例代碼

    本文介紹了在SpringBoot中獲取客戶端IP地址的幾種方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2024-11-11
  • Java實現(xiàn)的決策樹算法完整實例

    Java實現(xiàn)的決策樹算法完整實例

    這篇文章主要介紹了Java實現(xiàn)的決策樹算法,簡單描述了決策樹的概念、原理,并結(jié)合完整實例形式分析了java實現(xiàn)決策樹算法的相關操作技巧,代碼中備有較為詳盡的注釋便于理解,需要的朋友可以參考下
    2017-11-11
  • java開發(fā)就業(yè)信息管理系統(tǒng)

    java開發(fā)就業(yè)信息管理系統(tǒng)

    這篇文章主要為大家詳細介紹了java開發(fā)就業(yè)信息管理平臺,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-06-06
  • 使用IDEA創(chuàng)建java項目的步驟詳解(hello word)

    使用IDEA創(chuàng)建java項目的步驟詳解(hello word)

    這篇文章主要介紹了使用IDEA創(chuàng)建java項目的步驟詳解(hello word),本文分步驟通過圖文并茂的形式給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-12-12
  • @RereshScope刷新的原理詳解

    @RereshScope刷新的原理詳解

    在配合配置中心修改配置讓應用自動刷新配置時,我們要在需要感知配置變化的bean上面加上@RereshScope。如果我們不加上這注解,那么有可能無法完成配置自動刷新。本文就來和大家講講@RereshScope刷新的原理,需要的可以參考一下
    2022-12-12
  • Java對稱加密算法DES實例詳解

    Java對稱加密算法DES實例詳解

    這篇文章主要介紹了Java對稱加密算法DES,結(jié)合實例形式詳細分析了java DES算法的概念、原理、實現(xiàn)方法與應用場景,需要的朋友可以參考下
    2019-09-09
  • Java仿淘寶首頁分類列表功能的示例代碼

    Java仿淘寶首頁分類列表功能的示例代碼

    這篇文章主要介紹了仿淘寶分類管理功能的示例代碼,具有很好的參考價值,希望對大家有所幫助,也給大家做個參考
    2018-05-05
  • Java 對稱加密幾種算法分別實現(xiàn)

    Java 對稱加密幾種算法分別實現(xiàn)

    這篇文章主要介紹了Java 對稱加密使用DES / 3DES / AES 這三種算法分別實現(xiàn)的相關資料,這里提供了實例代碼,需要的朋友可以參考下
    2017-01-01
  • 自動配置@EnableAutoConfiguration問題

    自動配置@EnableAutoConfiguration問題

    這篇文章主要介紹了自動配置@EnableAutoConfiguration問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-06-06
  • Spring Boot Dubbo 構(gòu)建分布式服務的方法

    Spring Boot Dubbo 構(gòu)建分布式服務的方法

    這篇文章主要介紹了Spring Boot Dubbo 構(gòu)建分布式服務的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-05-05

最新評論