您好,登錄后才能下訂單哦!
這篇“MyBatis如何實現多表聯合查詢resultType的返回值”文章的知識點大部分人都不太理解,所以小編給大家總結了以下內容,內容詳細,步驟清晰,具有一定的借鑒價值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“MyBatis如何實現多表聯合查詢resultType的返回值”文章吧。
<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>
返回的類型是實體類,因為查詢結果數據均為實體類中字段的數據
<select id="queryNumber" resultType="io.renren.modules.generator.entity.TCarRunEntity"> select number from t_car_car where id = #{carid} </select>
返回的類型是實體類,因為查詢結果數據均為實體類中字段的數據
<select id="queryCar" resultType="io.renren.modules.generator.entity.TCarCarEntity"> select * from t_car_car </select>
t_car_car
t_car_driver
t_car_cardriver
t_car_cardriver存放的兩個字段分別是t_car_car和t_car_driver的主鍵id
1.resultType的返回類型是java.util.Map
返回得到的是List中存放的所有數據
<select id="queryDriver" resultType="java.util.Map"> select driverid from t_car_cardriver where carid = #{id} </select>
2.新建一個實體類
里面存放的是查詢結果里需要的字段名
// TCarCarDriver private Long carid; private Long driverid;
返回類型為該實體類
<select id="queryDriver" resultType="TCarCarDriver"> select driverid from t_car_cardriver where carid = #{id} </select>
多層集合嵌套返回結果用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>
以上就是關于“MyBatis如何實現多表聯合查詢resultType的返回值”這篇文章的內容,相信大家都有了一定的了解,希望小編分享的內容對大家有幫助,若想了解更多相關的知識內容,請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。