mybatis中根据多个Id批量修改数据库内容
先上代码,看是否能解决您的问题
controller
@PostMapping("/resetDevice")
public Object resetDevice(@RequestParam List list) {
try {
deviceService.resetDevice(list);
return ResultJson.ok();
} catch (Exception e) {
e.printStackTrace();
return ResultJson.failure(ResultCode.OPERATE_ERROR);
}
}
Mapper.xml
<update id="resetDevice" parameterType="java.util.List">
UPDATE alarm_info_statistics
set alarm_type='正常运行状态', is_normal=0
WHERE device_id in
<foreach collection="list" item="item" index="index" open="(" separator="," close=")">
#{item}
</foreach>
</update>
个人遇到的问题
1. Cannot generate variable name for non-typed Collection parameter type
遇到这个问题是说 “无法为非类型化集合参数类型生成变量名”
在遇到这个问题的时候有查询过资料,有的老哥是说要加泛型,我这边加了泛型也没有解决问题,于是就继续查询解决方法,我最后的解决方法是加了“@RequestParam()”,这个问题就解决了
当然过程并不是这么顺利,刚开始的时候加的是“@RequestBody”这个注解,
然后就出现了第二个问题
2. "Required request body is missing: public java.lang.Object com.modules.controller.DemoController.resetDevice(java.util.List)"
遇到这个问题大概是说,在你的这个这个方法中,缺少请求正文 ,你首先要确定一点,你前台传入的是否为一个json字符串的请求数据,是不是一个对象。
如果像我一样前台传入的只是一个list数组的话应该用@RequestParam()来接收参数。
如果您阅读本文后有一丢丢收获,点赞转发评论收藏,一键三连,谢谢你!