java~springboot~ibatis數組in查詢的實現
阿新 • • 發佈:2018-09-21
lec spring result ram 們的 沒有 close pen pda
在ibatis的xml文件裏,我們去寫sql語句,對應mapper類的方法,這些sql語句與控制臺上沒什麽兩樣,但在有些功能上需要註意,如where in
這種從數組裏查詢符合條件的集合裏,需要在xml裏進行特別的處理。
<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查詢的實現