# mybatis-plus中使用updateBatchById进行批量更新,对象中存储null会导致空指针异常报错

网上有很多的参考方案:

https://blog.csdn.net/qq_21223653/article/details/124877603

我记录一下,我使用的比较简单的方法,对我需要的字段进行更新

    @Autowired
    private DeviceService deviceService;
       
       for(Device device : devices){
            UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
            updateWrapper.eq("id",device.getId());
            updateWrapper.set("view_count",device.getViewCount());
            deviceService.update(null,updateWrapper);

        }
posted @ 2022-06-14 13:46  成强  阅读(3411)  评论(0编辑  收藏  举报