更新语句update table set dept_id=?,emp_code=? where id in (1,2,3);
1.接⼝
int batchUpdateEmpParams(@Param("list") List<Emp> list, @Param("deptId") String deptId,
@Param("empCode") String empCode);
<update id="batchUpdateEmpParams" parameterType="Map">
应力应变
测试update table
<set>
<if test="deptId!= null and deptId!= '' ">
dept_id = #{deptId,jdbcType=VARCHAR},
</if>
<if test="empCode!= null and empCode!= '' ">
小型干扰
芯片emp_code = #{empCode,jdbcType=VARCHAR}哇哈论坛
</if>
</set>
where id in
<foreach collection="list" index="index" item="item" open="(" separator="," close=")">
#{item.id,jdbcType=VARCHAR}
</foreach>
</update>
3.Emp.java
public class Emp implements Serializable {
private String id;
private String empCode;
private String deptId;
//getter setter
}空心砌块
4.控制器
/**
* 批量修改部门、code
* 员⼯id⽤英⽂逗号隔开如1,2,3
* @author kpzc
* @time 20181128
无边界网络
*/
@RequestMapping(value = "/xxx.json")
public void batchUpdateEmpParams(Emp emp,HttpServletRequest request) {
List<Emp> empList = new ArrayList<Emp>();
if(null!=emp){
String [] ids=null;
if(null!=Id()){
Id().split(",");
}
营养米
for (int i = 0; i < ids.length; i++) {
Emp e=new Emp();
e.setId(ids[i]);
empList.add(e);
}
}
int updateRows=0;
try{
updateRows = empMapper.batchUpdateEmpParams(empList, DeptId(), EmpCode()); }catch(Exception e){
e.printStackTrace();
//批量修改员⼯记录异常!
}
if (updateRows > 0) {
//批量修改员⼯记录成功
} }