im.shs.tick.mybatis.config.MybatisPlusConfig Maven / Gradle / Ivy
The newest version!
package im.shs.tick.mybatis.config;
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import im.shs.tick.mybatis.injector.CustomSqlInjector;
import org.apache.ibatis.type.EnumTypeHandler;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* MybatisPlus配置
*
* @author SimpleJuly
*/
@Configuration
public class MybatisPlusConfig {
/**
* 通用字段处理
*/
@Bean
@ConditionalOnMissingBean
public MybatisMetaObjectHandler metaObjectHandler() {
return new MybatisMetaObjectHandler();
}
/**
* 分页插件
*
* @return PaginationInterceptor
*/
@Bean
@ConditionalOnMissingBean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
/**
* 乐观锁插件
*/
@Bean
@ConditionalOnMissingBean
public OptimisticLockerInterceptor lockerInterceptor() {
return new OptimisticLockerInterceptor();
}
/**
* sql 注入
*/
@Bean
public ISqlInjector sqlInjector() {
return new CustomSqlInjector();
}
/**
* IEnum 枚举配置
*/
@Bean
public ConfigurationCustomizer configurationCustomizer() {
return new ConfigurationCustomizer() {
@Override
public void customize(org.apache.ibatis.session.Configuration configuration) {
configuration.setDefaultEnumTypeHandler(EnumTypeHandler.class);
}
};
}
}