|
-----------传入一个map---------批量修改数据---------------
controller中:
Map map = new HashMap();
map.put("notifyNum", notifyNum);
map.put("userIdArr", userIdArr);
userService.sendNotify(map);
sql中:
update user
set notify_codes=if(notify_codes is null or notify_codes='',#{notifyNum},CONCAT(notify_codes,',',#{notifyNum}))
where id in
#{item}
总结:
①这里传入了一个String notifyNum和一个String[] userIdArr ,我们只要在sql中名称匹配就可以了。
②批量修改也可以用in
③在修改的时候,我们可以在原来的字段值中直接后面追加字符串。当原来的值为数字的时候,我们可以 update user set notify_codes=notify_codes+'2' where id='24'
这样,假设原来为5,那么现在就为 7 了。
当原来的值是一个String类型时,我们可以用 CONCAT(notify_codes,',',#{notifyNum}) 来在后面追加 。比如原来为 "12" 现在最加一个 ",13" 那么结果为 "12,13"
④判断一个字段是否为空的时候,用这样用 if(notify_codes is null or notify_codes='','为空或空字符串返回这个值','非空的时候返回这个值')
|
|
|