mybatis注解如何實現對象批量更改
更新時間:2021年07月09日 14:42:06 作者:CoderYin
這篇文章主要介紹了mybatis注解實現對象批量更改的方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
mybatis注解對象批量更改
一、介紹
當有多個對象需要進行更改時,批量修改對象集合List
二、代碼
@Update("<script>"
+ "<foreach collection='listUserAnswerRecord' item='item' open='' close='' separator=';'> "
+ " update t_qb_record_201910"
+ " set answered = 0, progress = 1, answer_sheet = null, gmt_update = #{item.gmtUpdate}"
+ " <where>"
+ "<choose>"
+ "<when test='item.unionid !=null'> unionid=#{item.unionid}</when>"
+ "<otherwise> openid= #{item.openid} </otherwise>"
+ "</choose>"
+ " and goods_id = #{item.goodsId} and charpter_id = #{item.charpterId} and type = #{item.type}"
+ "</where>"
+ "</foreach>"
+ "</script>")
Integer deleteUserAnswerSheet(@Param("listUserAnswerRecord") List<UserAnswerRecordNew> listUserAnswerRecord);
mybatis 注解批量更新、插入
//批量插入
@Insert({
"<script>",
"insert into table(column1, column2) values ",
"<foreach collection='userLists' item='item' index='index' separator=','>",
"(#{item.column1}, #{item.column2} )",
"</foreach>",
"</script>"
})
public int insertUsers(@Param(value="userLists") List<User> userLists);
//批量更新
@Update({
"<script>",
"<foreach collection='userLists' item='item' index='index' separator=';'>",
"update table b",
"set b.column1= #{item.column1},b.column2= #{item.column2} where b.column3= #{item.column3}",
"</foreach>",
"</script>"
})
public int updateUser(@Param(value="userLists") List<User> userLists);
collection:你傳來的集合
item:里面的類
index:就是for循環(huán)的i
separator:間隔符
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
springboot docker jenkins 自動化部署并上傳鏡像的步驟詳解
這篇文章主要介紹了springboot docker jenkins 自動化部署并上傳鏡像的相關資料,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-05-05
spring boot security設置忽略地址不生效的解決
這篇文章主要介紹了spring boot security設置忽略地址不生效的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-07-07
SpringBoot使用validation做參數校驗的實現步驟
這篇文章主要介紹了SpringBoot使用validation做參數校驗的實現步驟,幫助大家更好的理解和學習使用SpringBoot,感興趣的朋友可以了解下2021-05-05
springboot使用mybatis一對多的關聯查詢問題記錄
這篇文章主要介紹了springboot使用mybatis一對多的關聯查詢問題記錄,剛好最近有個需求需要做到關聯的查詢,時間也算充足,所以用sql來寫,于是踩了很久坑,終于跳出來了,小小記錄一下2022-01-01

