您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“mybatis分割字符串并循環(huán)實現(xiàn)in多個參數(shù)的示例分析”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“mybatis分割字符串并循環(huán)實現(xiàn)in多個參數(shù)的示例分析”這篇文章吧。
mybatis xml代碼:
<select id="selectInXh" resultMap="BaseResultMap" parameterType="java.lang.String"> select * from carinfo where xh in <if test="param1 != null and param1 != ''"> <foreach item="item" index="index" collection="param1.split(',')" open="(" separator="," close=")"> #{item} </foreach> </if> </select>
mybatis sql打?。?/p>
==> Preparing: select * from carinfo where xh in ( ? , ? ) ==> Parameters: 1(String), 2(String)
List<AnalysisInfo> listInfo(@Param("orderIds") List<Integer> orderIds);
我這里對參數(shù)重命名為"orderIds",所以下面foreach中collection="orderIds",如果未重命名則foreach中collection="list"
<select id="listInfo" resultType="com.ieou.retail.module.H5.dto.AnalysisInfo"> select materials_name as materialsName,sum(num) as totalNum, sum(price) as totalSale from sales_order_detail where shipment_result = 'SUCCESS' and refunds_time is null and sales_order_id in <foreach collection="orderIds" index="index" item="item" open="(" separator="," close=")"> #{item} </foreach> group by materials_id order by totalNum desc limit 5 </select>
List<AnalysisInfo> listInfo(Long[] orderIds);
如果參數(shù)類型是Array則collection屬性為array
<select id="listInfo" resultType="com.ieou.retail.module.H5.dto.AnalysisInfo"> select materials_name as materialsName,sum(num) as totalNum, sum(price) as totalSale from sales_order_detail where shipment_result = 'SUCCESS' and refunds_time is null and sales_order_id in <foreach collection="array" index="index" item="item" open="(" separator="," close=")"> #{item} </foreach> group by materials_id order by totalNum desc limit 5 </select>
List<AnalysisInfo> listInfo(List<Integer> orderIds, Integer num);
這種情況下傳參要使用Map方式,這樣在collection屬性可以指定名稱
Map<String, Object> params = new HashMap<>(); params.put("orderIds",orderIds); params.put("num",num); List<AnalysisInfo> listInfo(params);
XML如下:
<select id="listInfo" resultType="com.ieou.retail.module.H5.dto.AnalysisInfo"> select materials_name as materialsName,sum(num) as totalNum, sum(price) as totalSale from sales_order_detail where shipment_result = 'SUCCESS' and refunds_time is null and num = #{num} and sales_order_id in <foreach collection="orderIds" index="index" item="item" open="(" separator="," close=")"> #{item} </foreach> group by materials_id order by totalNum desc limit 5 </select>
以上是“mybatis分割字符串并循環(huán)實現(xiàn)in多個參數(shù)的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。