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

MyBatis實(shí)現(xiàn)多表聯(lián)合查詢r(jià)esultType的返回值

 更新時(shí)間:2022年03月10日 17:17:23   作者:aloofAnd  
這篇文章主要介紹了MyBatis多表聯(lián)合查詢r(jià)esultType的返回值,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

多表聯(lián)合查詢r(jià)esultType的返回值

一般數(shù)據(jù)按參數(shù)類型返回

<select id="queryCarIdList" resultType="long">
? ? ? ? select id from t_car_car
</select>
? <select id="queryDept" resultType="string">
? ? ? ? SELECT deptname FROM t_car_run where deptid = #{deptid} GROUP BY deptname
? ? </select>

根據(jù)某字段查詢

返回的類型是實(shí)體類,因?yàn)椴樵兘Y(jié)果數(shù)據(jù)均為實(shí)體類中字段的數(shù)據(jù)

<select id="queryNumber" resultType="io.renren.modules.generator.entity.TCarRunEntity">
? ? ? ? select number from t_car_car where id = #{carid}
</select>

查詢結(jié)果為多條記錄,存放在list中返回

返回的類型是實(shí)體類,因?yàn)椴樵兘Y(jié)果數(shù)據(jù)均為實(shí)體類中字段的數(shù)據(jù)

<select id="queryCar" resultType="io.renren.modules.generator.entity.TCarCarEntity">
? ? ? ? select * from t_car_car
</select>

多表聯(lián)合查詢

  • t_car_car
  • t_car_driver
  • t_car_cardriver

t_car_cardriver存放的兩個(gè)字段分別是t_car_car和t_car_driver的主鍵id

解決方案

1.resultType的返回類型是java.util.Map

返回得到的是List中存放的所有數(shù)據(jù)

<select id="queryDriver" resultType="java.util.Map">
? ? ? ? select driverid from t_car_cardriver where carid = #{id}
</select>

2.新建一個(gè)實(shí)體類

里面存放的是查詢結(jié)果里需要的字段名

// TCarCarDriver
private Long carid;
private Long driverid;

返回類型為該實(shí)體類

<select id="queryDriver" resultType="TCarCarDriver">
? ? ? ? select driverid from t_car_cardriver where carid = #{id}
</select>

多表聯(lián)查,返回結(jié)果嵌套list

多層集合嵌套返回結(jié)果用resultMap,collection中再次使用resultMap

<resultMap id="chainVo" type="com.suncnpap.intelligentqa.vo.ChainVo">
? ? <id column="cid" property="id"/>
? ? <result column="access_key" property="accessKey"/>
? ? <result column="secret_key" property="secretKey"/>
? ? <result column="outer_chain_name" property="outerChainName"/>
? ? <result column="outer_chain_document" property="outerChainDocument"/>
? ? <collection property="intentionVos" ofType="com.suncnpap.intelligentqa.vo.ChainIntentionVo"
? ? ? ? ? ? ? ? resultMap="intentionVos"/>
</resultMap>
?
<resultMap id="intentionVos" type="com.suncnpap.intelligentqa.vo.ChainIntentionVo">
? ? <id column="iid" property="id"/>
? ? <result column="intention_name" property="intentionName"/>
? ? <collection property="questionVoList" ofType="com.suncnpap.intelligentqa.vo.MultiQuestionVo">
? ? ? ? <id column="qid" property="id"/>
? ? ? ? <result column="question" property="question"/>
? ? </collection>
? ? <collection property="wordVos" ofType="com.suncnpap.intelligentqa.vo.ChainIntentionWordVo">
? ? ? ? <id column="wid" property="id"/>
? ? ? ? <result column="word_slot" property="wordSlot"/>
? ? ? ? <result column="word_slot_miss_question" property="wordSlotMissQuestion"/>
? ? ? ? <result column="entity_type_ids" property="entityTypeIds"/>
? ? </collection>
</resultMap>
?
<select id="detail" resultMap="chainVo">
? ? select tc.id ? as tid,
? ? ? ? ? ?tci.id ?as iid,
? ? ? ? ? ?tciw.id as wid,
? ? ? ? ? ?tmq.id ?as qid,
? ? ? ? ? ?access_key,
? ? ? ? ? ?secret_key,
? ? ? ? ? ?outer_chain_name,
? ? ? ? ? ?outer_chain_document,
? ? ? ? ? ?intention_name,
? ? ? ? ? ?question,
? ? ? ? ? ?word_slot,
? ? ? ? ? ?word_slot_miss_question,
? ? ? ? ? ?entity_type_ids
? ? from t_chain tc
? ? ? ? ? ? ?left join t_chain_intention tci on tc.id = tci.chain_id
? ? ? ? ? ? ?left join t_chain_intention_word tciw on tci.id = tciw.intention_id
? ? ? ? ? ? ?left join t_multi_question tmq on tci.id = tmq.parent_id
? ? where tc.id = #{id}
? ? ? and tc.deleted = 0
</select>

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • springcloud本地調(diào)試feign調(diào)用出現(xiàn)的詭異404問題及解決

    springcloud本地調(diào)試feign調(diào)用出現(xiàn)的詭異404問題及解決

    這篇文章主要介紹了springcloud本地調(diào)試feign調(diào)用出現(xiàn)的詭異404問題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • SpringBoot整合Spring?Data?JPA的詳細(xì)方法

    SpringBoot整合Spring?Data?JPA的詳細(xì)方法

    JPA全稱為Java Persistence API(Java持久層API),是一個(gè)基于ORM的標(biāo)準(zhǔn)規(guī)范,在這個(gè)規(guī)范中,JPA只定義標(biāo)準(zhǔn)規(guī)則,不提供實(shí)現(xiàn),本文重點(diǎn)給大家介紹SpringBoot整合Spring?Data?JPA的相關(guān)知識(shí),感興趣的朋友一起看看吧
    2022-02-02
  • SpringBoot中緩存注解的使用詳解

    SpringBoot中緩存注解的使用詳解

    為了實(shí)現(xiàn)緩存,Spring?Boot?提供了一些緩存注解,可以方便地實(shí)現(xiàn)緩存功能,這篇文章主要介紹了SpringBoot中常用的緩存注解的使用方法,需要的可以參考一下
    2023-06-06
  • Java泛型 <T> T、 T、<T>的用法小結(jié)

    Java泛型 <T> T、 T、<T>的用法小結(jié)

    T在Java泛型中,被稱作類型變量, 有的方法返回值是<T> T,有的是T,區(qū)別在哪里,本文主要介紹了Java泛型 <T> T、 T、<T>的用法小結(jié),具有一定的參考價(jià)值,感興趣的可以了解下
    2023-12-12
  • 編程語言榜單Java與Python并列第二!Julia下滑

    編程語言榜單Java與Python并列第二!Julia下滑

    日新月異的技術(shù)圈,隨著云、大數(shù)據(jù)、人工智能等主流技術(shù)的廣泛應(yīng)用,作為開發(fā)利器的編程語言的最新發(fā)展趨勢也在無形中發(fā)生了變化,本文主要介紹了java、Python、Julia等語言在Resmonk榜單的排名
    2021-08-08
  • 詳解Struts2中配置默認(rèn)Action的方法

    詳解Struts2中配置默認(rèn)Action的方法

    本篇文章主要介紹了詳解Struts2中配置默認(rèn)Action的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-01-01
  • Java DOM4J方式生成XML的方法

    Java DOM4J方式生成XML的方法

    今天小編就為大家分享一篇Java DOM4J方式生成XML的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-07-07
  • java遍歷讀取xml文件內(nèi)容

    java遍歷讀取xml文件內(nèi)容

    這篇文章主要為大家介紹了java遍歷讀取xml文件內(nèi)容,感興趣的小伙伴們可以參考一下
    2016-01-01
  • 基于IntelliJ IDEA的類注釋和方法注釋操作

    基于IntelliJ IDEA的類注釋和方法注釋操作

    這篇文章主要介紹了基于IntelliJ IDEA的類注釋和方法注釋操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • idea熱部署且開啟自動(dòng)編譯的實(shí)現(xiàn)方法

    idea熱部署且開啟自動(dòng)編譯的實(shí)現(xiàn)方法

    這篇文章主要介紹了idea熱部署且開啟自動(dòng)編譯的實(shí)現(xiàn)方法,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-12-12

最新評(píng)論