<update id="updateCaStores">
<foreach separator=";" collection="list" item="c" index="index">
update cake
<set>
caStore=#{c.caStore}
</set>
where id =#{c.id}
</foreach>
</update>
有一点要注意,如果运用了,<set></set>语法,来mysql的批量更新是要我们主动去设置的,需要在配置数据库连接地址中加上&allowMultiQueries=true
jdbcDriver=com.mysql.jdbc.Driver
jdbcUrl=jdbc:mysql:///cake?characterEncoding=utf-8&allowMultiQueries=true
jdbcusername=root
jdbcpassword=1
相应的dao
public interface CakeDao {
int updateCaStores(List<Cake> list);
}
相应的pojo
package com.ca.pojo;
import java.io.Serializable;
public class Cake implements Serializable{
private static final long serialVersionUID = 9008588971168496311L;
private Integer id;
//蛋糕名
private String caName;
//库存
private Integer caStore;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getCaName() {
return caName;
}
public void setCaName(String caName) {
this.caName = caName;
}
public Integer getCaStore() {
return caStore;
}
public void setCaStore(Integer caStore) {
this.caStore = caStore;
}
}