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语句

Mybatis-Plus根据条件更新

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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-08
  • 2021-09-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案