美文网首页
使用mybatis-plus使用逻辑删除插件和分页插件

使用mybatis-plus使用逻辑删除插件和分页插件

作者: 任笙_8b8c | 来源:发表于2021-05-11 09:21 被阅读0次
分页插件

步骤:

  • 1.在config类中MybatisPlusConfig注入bean
  /*分页插件*/
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }

测试:

  /*测试分页插件*/
    @Test
    void contextLoad13( ) {
        HashMap<String, Object> Map = new HashMap<>();
        Map.put("name","测试一");

        Page<User> page = new Page(1,2);
        IPage<User> userIPage = userMapper.selectPage(page, null);

        System.out.println(userIPage.getTotal());

        userIPage.getRecords().forEach(System.out::print);

    }
图片.png
逻辑删除插件

步骤:

  • 1.在application.properties中添加
#配置逻辑删除 删除1  为删除0 flag需要逻辑删除的字段
mybatis-plus.global-config.db-config.logic-delete-field=flag
mybatis-plus.global-config.db-config.logic-delete-value=1
mybatis-plus.global-config.db-config.logic-not-delete-value=0
  • 2.在实体中加
 /*逻辑删除注解*/
        @TableLogic
        private Integer flag;
  • 3.代码
    /*测试逻辑删除*/
    @Test
    void contextLoad14( ) {

       userMapper.deleteById(5L);

    }
图片.png

坑:Mybatis plus逻辑删除失败的BUG操作 报错:什么什么版本错误
解决:
升级Mybatis plus版本到3.2.0

 <!--mybatis-plus-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.2.0</version>
        </dependency>

报错:日志打印乱码


图片.png

看配置文件是不是 加了中文

相关文章

网友评论

      本文标题:使用mybatis-plus使用逻辑删除插件和分页插件

      本文链接:https://www.haomeiwen.com/subject/lyiidltx.html