mybatisplus

发布时间 2023-08-13 13:32:02作者: Nzy6

注解
@TableId(type = IdType.AUTO) 表示主键自增
@TableField(value = "create_time") 表示字段"()"里的value对应数据库的表名
@TableLogic 逻辑删除

mapper接口创建

service接口创建

serviceImpl类创建

配置分页插件:创建一个类,在类上面标注注解并在类中实现官方给的方法
@Configuration
@MapperScan("com.atguigu.auth.mapper")
public class MybatisPlusConfig {

/**
 * 新的分页插件,一缓和二缓遵循mybatis的规则,需要设置 MybatisConfiguration#useDeprecatedExecutor = false 避免缓存出现问题(该属性会在旧插件移除后一同移除)
 */
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
    MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
    interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
    return interceptor;
}

@Bean
public ConfigurationCustomizer configurationCustomizer() {
    return configuration -> configuration.setUseDeprecatedExecutor(false);
}

}