Mybatis 傳輸List的實(shí)現(xiàn)代碼
1. 當(dāng)查詢的參數(shù)只有一個(gè)時(shí)
findByIds(List<Long> ids)
1.1 如果參數(shù)的類型是List, 則在使用時(shí),collection屬性要必須指定為 list
Xml代碼
<select id="findByIdsMap" resultMap="BaseResultMap"> Select <include refid="Base_Column_List" /> from jria where ID in <foreach item="item" index="index" collection="list" open="(" separator="," close=")"> #{item} </foreach> </select> <select id="findByIdsMap" resultMap="BaseResultMap"> Select <include refid="Base_Column_List" /> from jria where ID in <foreach item="item" index="index" collection="list" open="(" separator="," close=")"> #{item} </foreach> </select> findByIds(Long[] ids)
1.2 如果參數(shù)的類型是Array,則在使用時(shí),collection屬性要必須指定為 array
Xml代碼
<select id="findByIdsMap" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from tabs where ID in <foreach item="item" index="index" collection="array" open="(" separator="," close=")"> #{item} </foreach> </select> <select id="findByIdsMap" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from tabs where ID in <foreach item="item" index="index" collection="array" open="(" separator="," close=")"> #{item} </foreach> </select>
2. 當(dāng)查詢的參數(shù)有多個(gè)時(shí),例如 findByIds(String name, Long[] ids)
這種情況需要特別注意,在傳參數(shù)時(shí),一定要改用Map方式, 這樣在collection屬性可以指定名稱
下面是一個(gè)示例
Map<String, Object> params = new HashMap<String, Object>(2); params.put("name", name); params.put("ids", ids); mapper.findByIdsMap(params);
Xml代碼
<select id="findByIdsMap" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from tabs where ID in <foreach item="item" index="index" collection="ids" open="(" separator="," close=")"> #{item} </foreach> </select>
總結(jié)
以上所述是小編給大家介紹的Mybtis 傳輸List的實(shí)現(xiàn)代碼,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
SpringBoot整合EasyExcel實(shí)現(xiàn)導(dǎo)入導(dǎo)出數(shù)據(jù)
這篇文章主要為大家詳細(xì)介紹了如何使用Vue、SpringBoot和EasyExcel實(shí)現(xiàn)導(dǎo)入導(dǎo)出數(shù)據(jù)功能,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2022-05-05jdk-logging?log4j?logback日志系統(tǒng)實(shí)現(xiàn)機(jī)制原理介紹
這篇文章主要介紹了jdk-logging、log4j、logback日志介紹以及三個(gè)日志系統(tǒng)的實(shí)現(xiàn)機(jī)制,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-03-03MyBatis JdbcType 與Oracle、MySql數(shù)據(jù)類型對(duì)應(yīng)關(guān)系說明
這篇文章主要介紹了MyBatis JdbcType 與Oracle、MySql數(shù)據(jù)類型對(duì)應(yīng)關(guān)系說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-09-09使用Spring Boot創(chuàng)建Web應(yīng)用程序的示例代碼
本篇文章主要介紹了使用Spring Boot創(chuàng)建Web應(yīng)用程序的示例代碼,我們將使用Spring Boot構(gòu)建一個(gè)簡單的Web應(yīng)用程序,并為其添加一些有用的服務(wù),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-05-05關(guān)于protected修飾符詳解-源于Cloneable接口
這篇文章主要介紹了protected修飾符詳解-源于Cloneable接口,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-11-11