mybatis 批量更新update

使用mybatis逆向工程生成的Example处理批量逻辑删除update

  /*

  将前端接收的id集合拼接的字符串解析

  */

String idListStr = baseConditions.getIdList();
String[] idStrList = idListStr.split(",");

List<Integer> integerList = new ArrayList<Integer>();
for (int i = 0; i < idStrList.length; i++) {
Integer id = Integer.parseInt(idStrList[i]);
integerList.add(id);
}

  /*

  要修改的信息

  */

//修改人,修改时间
RoleDO roleDO = new RoleDO();
roleDO.setModifier(baseConditions.getAdminId());
roleDO.setModifyTime(new Date());
roleDO.setIsDeleted(2);
/*
Example是where的条件,需要update的主键集合List
*/
RoleDOExample roleDOExample = new RoleDOExample();
roleDOExample.createCriteria().andIdIn(integerList);
int i = roleDOMapper.updateByExampleSelective(roleDO, roleDOExample);

*sql语句类似
update role set modifier=#{},modify_time =#{},is_deleted=2 where id in(1,3,5);
逆向工程的Example使用的详解
https://blog.csdn.net/biandous/article/details/65630783

猜你喜欢

转载自www.cnblogs.com/draymond/p/10327819.html
今日推荐