zoukankan      html  css  js  c++  java
  • 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

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

    自我控制是最强者的本能-萧伯纳
  • 相关阅读:
    spring ref &history&design philosophy
    LDAP & Implementation
    REST
    隔离级别
    Servlet Analysis
    Session&Cookie
    Dvelopment descriptor
    write RE validation
    hello2 source anaylis
    Filter
  • 原文地址:https://www.cnblogs.com/CF1314/p/13985003.html
Copyright © 2011-2022 走看看