分页插件
步骤:
- 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);
}

逻辑删除插件
步骤:
- 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);
}

坑: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>
报错:日志打印乱码

看配置文件是不是 加了中文
网友评论