1、在config文件夹下创建MybatisPlusConfig类
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@MapperScan("com.jk193_ky.usermanage.dao")
public class MybatisPlusConfig {
/**
* 新的分页插件,一缓和二缓遵循mybatis的规则,需要设置 MybatisConfiguration#useDeprecatedExecutor = false 避免缓存出现问题(该属性会在旧插件移除后一同移除)
*/
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
// DbType.数据库类型 使用什么数据库就填什么
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
@Bean
public ConfigurationCustomizer configurationCustomizer() {
return configuration -> configuration.setUseDeprecatedExecutor(false);
}
}
2、在service文件夹下的相关类(如UserService)继承ServiceImpl
参数一:相对应的持久层接口
参数二:相对应的实体类
public class UserService extends ServiceImpl<UserDao, User> {
3、在相对应的持久层接口继承BaseMapper
参数:相对应的实体类
public interface UserDao extends BaseMapper<User>
4、在application.iml下添加
mybatis-plus:
configuration:
# 用mybatis plus时打印sql语句
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl