Search in sources :

Example 1 with DefaultSqlInjector

use of com.baomidou.mybatisplus.core.injector.DefaultSqlInjector in project mybatis-plus-samples by baomidou.

the class MybatisPlusConfig method globalConfig.

@Bean
public GlobalConfig globalConfig() {
    GlobalConfig conf = new GlobalConfig();
    conf.setDbConfig(new GlobalConfig.DbConfig().setColumnFormat("`%s`"));
    DefaultSqlInjector logicSqlInjector = new DefaultSqlInjector() {

        /**
         * 注入自定义全局方法
         */
        @Override
        public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
            List<AbstractMethod> methodList = super.getMethodList(mapperClass, tableInfo);
            // 不要逻辑删除字段, 不要乐观锁字段, 不要填充策略是 UPDATE 的字段
            methodList.add(new InsertBatchSomeColumn(t -> !t.isLogicDelete() && !t.isVersion() && t.getFieldFill() != FieldFill.UPDATE));
            // 不要填充策略是 INSERT 的字段, 不要字段名是 column4 的字段
            methodList.add(new AlwaysUpdateSomeColumnById(t -> t.getFieldFill() != FieldFill.INSERT && !t.getProperty().equals("column4")));
            return methodList;
        }
    };
    conf.setSqlInjector(logicSqlInjector);
    return conf;
}
Also used : OptimisticLockerInnerInterceptor(com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor) InsertBatchSomeColumn(com.baomidou.mybatisplus.extension.injector.methods.InsertBatchSomeColumn) AbstractMethod(com.baomidou.mybatisplus.core.injector.AbstractMethod) GlobalConfig(com.baomidou.mybatisplus.core.config.GlobalConfig) MapperScan(org.mybatis.spring.annotation.MapperScan) Configuration(org.springframework.context.annotation.Configuration) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) MybatisConfiguration(com.baomidou.mybatisplus.core.MybatisConfiguration) MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) MybatisPlusInterceptor(com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor) List(java.util.List) TableInfo(com.baomidou.mybatisplus.core.metadata.TableInfo) MybatisMapWrapperFactory(com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) DataSource(javax.sql.DataSource) FieldFill(com.baomidou.mybatisplus.annotation.FieldFill) AlwaysUpdateSomeColumnById(com.baomidou.mybatisplus.extension.injector.methods.AlwaysUpdateSomeColumnById) JdbcType(org.apache.ibatis.type.JdbcType) Bean(org.springframework.context.annotation.Bean) DefaultSqlInjector(com.baomidou.mybatisplus.core.injector.DefaultSqlInjector) PaginationInnerInterceptor(com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor) GlobalConfig(com.baomidou.mybatisplus.core.config.GlobalConfig) AbstractMethod(com.baomidou.mybatisplus.core.injector.AbstractMethod) DefaultSqlInjector(com.baomidou.mybatisplus.core.injector.DefaultSqlInjector) TableInfo(com.baomidou.mybatisplus.core.metadata.TableInfo) InsertBatchSomeColumn(com.baomidou.mybatisplus.extension.injector.methods.InsertBatchSomeColumn) AlwaysUpdateSomeColumnById(com.baomidou.mybatisplus.extension.injector.methods.AlwaysUpdateSomeColumnById) MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

FieldFill (com.baomidou.mybatisplus.annotation.FieldFill)1 MybatisConfiguration (com.baomidou.mybatisplus.core.MybatisConfiguration)1 GlobalConfig (com.baomidou.mybatisplus.core.config.GlobalConfig)1 AbstractMethod (com.baomidou.mybatisplus.core.injector.AbstractMethod)1 DefaultSqlInjector (com.baomidou.mybatisplus.core.injector.DefaultSqlInjector)1 TableInfo (com.baomidou.mybatisplus.core.metadata.TableInfo)1 MybatisMapWrapperFactory (com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory)1 AlwaysUpdateSomeColumnById (com.baomidou.mybatisplus.extension.injector.methods.AlwaysUpdateSomeColumnById)1 InsertBatchSomeColumn (com.baomidou.mybatisplus.extension.injector.methods.InsertBatchSomeColumn)1 MybatisPlusInterceptor (com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor)1 OptimisticLockerInnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor)1 PaginationInnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor)1 MybatisSqlSessionFactoryBean (com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean)1 List (java.util.List)1 DataSource (javax.sql.DataSource)1 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)1 JdbcType (org.apache.ibatis.type.JdbcType)1 MapperScan (org.mybatis.spring.annotation.MapperScan)1 Bean (org.springframework.context.annotation.Bean)1 Configuration (org.springframework.context.annotation.Configuration)1