Mybatis傳入List實(shí)現(xiàn)批量更新的示例代碼
Dao層寫法
/** * 批量更新新庫存 * @param list * @return */ int updateNewStock(@Param(value = 'list') List<GreenBeanMsg> list);
xml具體實(shí)現(xiàn)代碼
<update parameterType='java.util.List'> <foreach collection='list' item='bean' index='index' open='' close='' separator=';'> UPDATE green_beans <set>stock=#{bean.stock} </set> <where>beanUid = #{bean.beanUid} </where> </foreach> </update>
注意的地方:我傳入的是一個(gè)集合,于是在dao層寫的方法里加上@Param(value“l(fā)ist”),mybatis將傳入的參數(shù)看做是一個(gè)集合list了。于是,在foreach中的collectio中就要寫作“l(fā)ist”;parameterType也定義為'java.util.List'。
注意:這種方法必須在配置連接數(shù)據(jù)庫url后面帶一個(gè)參數(shù) &allowMultiQueries=true,表示允許批量操作,例 jdbc:mysql://localhost:3306/mysqlTest?characterEncoding=utf-8&allowMultiQueries=true
到此這篇關(guān)于Mybatis傳入List實(shí)現(xiàn)批量更新的示例代碼的文章就介紹到這了,更多相關(guān)Mybatis傳入List批量更新內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. SQL Server全文檢索簡介2. Docker部署Mysql集群的實(shí)現(xiàn)3. Oracle中pivot函數(shù)圖文實(shí)例詳解4. MySQL 的啟動和連接方式實(shí)例分析5. Oracle 9i輕松取得建表和索引DDL語句6. 服務(wù)器Centos部署MySql并連接Navicat過程詳解7. idea連接SQL Server數(shù)據(jù)庫的詳細(xì)圖文教程8. SQL SERVER數(shù)據(jù)庫開發(fā)之存儲過程的應(yīng)用9. 在SQL Server 2005修改存儲過程10. Oracle?Users表空間重命名問題解決
