1. 程式人生 > >mybatis 批量更新update

mybatis 批量更新update

ref list mybatis admin dom 字符串 reat blog 邏輯

使用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

mybatis 批量更新update