在ibatis的xml文件里,我們去寫sql語句,對應mapper類的方法,這些sql語句與控制臺上沒什么兩樣,但在有些功能上需要注意,如where in這種從數組里查詢符合條件的集合里,需要在xml里進行特別的處理。
1
2
3
4
5
6
7
8
|
<update id= "batchupdate" parametertype= "map" > update customer_info set status=#{status},appoint_time=#{appointtime} where customer_id in <foreach collection= "customeridarr" item= "customerid" index= "index" open= "(" close= ")" separator= "," > #{customerid} </foreach> </update> |
我們可以看到,在xml里進行了foreach的遍歷,而外部參數是一個集合或者數組的對象,我們在xml對它進行遍歷,還是比較方便的。
技巧:在xml里,parametertype是輸入參數類型,你可以使用map對象來代替;而resulttype是返回類型,如果你沒有定義dto也可以使用map代替,雖然map可以讓我們的代碼變簡潔,當然也有缺陷,就是會寫很多弱類型的屬性名。
總結
以上所述是小編給大家介紹的java~springboot~ibatis數組in查詢的實現方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對服務器之家網站的支持!