# 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 @   成强  阅读(3635)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示