1、前言

为了防止在代码中错误的使用Mybatis进行了全表的更新和删除操作,我们可以通过Mybatis进行配置

2、注入MybatisPlusInterceptor

  • 重点是BlockAttackInnerInterceptor
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
    MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
    PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
    // 阻止全表更新与删除
    BlockAttackInnerInterceptor blockAttackInnerInterceptor = new BlockAttackInnerInterceptor();
    // 设置请求的页面大于最大页后操作, true调回到首页,false 继续请求  默认false
    paginationInnerInterceptor.setOverflow(true);
    paginationInnerInterceptor.setMaxLimit(200L);
    interceptor.addInnerInterceptor(paginationInnerInterceptor);
    interceptor.addInnerInterceptor(blockAttackInnerInterceptor);
    return interceptor;
}

3、测试

  • 更新操作测试

1-更新操作.png

  • 删除操作

1-删除操作.png