https://nannan408.iteye.com/blog/2170470java
https://blog.csdn.net/xingzhishen/article/details/86424395sql
參數的數據結構是一個ArrayList<Map<String, Integer>>,須要以String,Integer爲條件批量更新數據庫的數據.數據庫
將參數封裝到叫作JsonData的qv中,JsonData的關鍵代碼是json
private ArrayList<Map<String, Integer>> usersPlatforms;
public ArrayList<Map<String, Integer>> getUsersPlatforms() {
return usersPlatforms;
}
public void setUsersPlatforms(ArrayList<Map<String, Integer>> usersPlatforms) {
this.usersPlatforms = usersPlatforms;
}
Mapper中的方法是:數據結構
updateXxxx(JsonData jsonData);
Mapper.xml的sql是:app
<update id="updateXxxx" parameterType="JsonData">
UPDATE xxx SET `xx` = 10
<where>
<foreach collection="usersPlatforms" item="userPlatform" open="" close="" separator="OR">
<foreach collection="userPlatform.keys" item="key" open=" user_id = " close="" separator="">
#{key}
</foreach>
<foreach collection="userPlatform.values" item="value" open=" AND platform = " close="" separator="">
#{value}
</foreach>
</foreach>
</where>
</update>
----------------------------------- ----------------------------------- ----------------------------------- -----------------------------------測試
1.前言.
如題.
2.代碼.
(1)mapper.xml. this
(2)interface spa
(3)
測試類: .net
2.批量更新.
大部分傳list就能夠了,傳map也能夠,但map也要解析成list,能夠自行研究map,這裏介紹通用的list傳值方法:
(1)mapper
(2)xml
(3)測試類