Mybatis-Plus根据条件更新


Mybatis-Plus根据条件更新

在 Mybatis-Plus 项目中,很多时候需要根据条件更新特定的数据行,这时候可以使用到提供的 update() 方法。

下面以 PostCategories 对象为例简单演示下使用的方法。

1、创建对象并填入要更新的字段数据

例如更新 homePage 字段值为 false

PostCategories updateMessage = new PostCategories();
updateMessage.setHomePage(false);

2、创建条件构造器和查询条件

new QueryWrapper () 为条件构造器;

eq("homePage", true) 即是查询条件: where homePage = true,条件根据需要添加。

postCategoriesMapper.update(updateMessage, new QueryWrapper<PostCategories>().eq("homePage", true));

3、查看打印的sql语句

image-20201116144348357

这样就达到了条件更新的目的。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM