mybatis批量修改

mybatis批量修改只执⾏⼀条语句批量更新
更新语句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) {
    //批量修改员⼯记录成功
    }  }

本文发布于:2024-09-23 18:33:08,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/1/193292.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:批量   修改   测试   芯片
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议