Search in sources :

Example 1 with AlwaysUpdateSomeColumnById

use of com.baomidou.mybatisplus.extension.injector.methods.AlwaysUpdateSomeColumnById 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)

Example 2 with AlwaysUpdateSomeColumnById

use of com.baomidou.mybatisplus.extension.injector.methods.AlwaysUpdateSomeColumnById in project mybatis-plus-samples by baomidou.

the class MySqlInjector method getMethodList.

@Override
public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
    List<AbstractMethod> methodList = super.getMethodList(mapperClass, tableInfo);
    // 增加自定义方法
    methodList.add(new DeleteAll());
    methodList.add(new FindOne());
    /**
     * 以下 3 个为内置选装件
     * 头 2 个支持字段筛选函数
     */
    // 例: 不要指定了 update 填充的字段
    methodList.add(new InsertBatchSomeColumn(i -> i.getFieldFill() != FieldFill.UPDATE));
    methodList.add(new AlwaysUpdateSomeColumnById());
    methodList.add(new LogicDeleteByIdWithFill());
    return methodList;
}
Also used : FindOne(com.baomidou.samples.injector.methods.FindOne) List(java.util.List) TableInfo(com.baomidou.mybatisplus.core.metadata.TableInfo) FindOne(com.baomidou.samples.injector.methods.FindOne) InsertBatchSomeColumn(com.baomidou.mybatisplus.extension.injector.methods.InsertBatchSomeColumn) FieldFill(com.baomidou.mybatisplus.annotation.FieldFill) AbstractMethod(com.baomidou.mybatisplus.core.injector.AbstractMethod) AlwaysUpdateSomeColumnById(com.baomidou.mybatisplus.extension.injector.methods.AlwaysUpdateSomeColumnById) LogicDeleteByIdWithFill(com.baomidou.mybatisplus.extension.injector.methods.LogicDeleteByIdWithFill) DeleteAll(com.baomidou.samples.injector.methods.DeleteAll) DefaultSqlInjector(com.baomidou.mybatisplus.core.injector.DefaultSqlInjector) DeleteAll(com.baomidou.samples.injector.methods.DeleteAll) AbstractMethod(com.baomidou.mybatisplus.core.injector.AbstractMethod) InsertBatchSomeColumn(com.baomidou.mybatisplus.extension.injector.methods.InsertBatchSomeColumn) LogicDeleteByIdWithFill(com.baomidou.mybatisplus.extension.injector.methods.LogicDeleteByIdWithFill) AlwaysUpdateSomeColumnById(com.baomidou.mybatisplus.extension.injector.methods.AlwaysUpdateSomeColumnById)

Aggregations

FieldFill (com.baomidou.mybatisplus.annotation.FieldFill)2 AbstractMethod (com.baomidou.mybatisplus.core.injector.AbstractMethod)2 DefaultSqlInjector (com.baomidou.mybatisplus.core.injector.DefaultSqlInjector)2 TableInfo (com.baomidou.mybatisplus.core.metadata.TableInfo)2 AlwaysUpdateSomeColumnById (com.baomidou.mybatisplus.extension.injector.methods.AlwaysUpdateSomeColumnById)2 InsertBatchSomeColumn (com.baomidou.mybatisplus.extension.injector.methods.InsertBatchSomeColumn)2 List (java.util.List)2 MybatisConfiguration (com.baomidou.mybatisplus.core.MybatisConfiguration)1 GlobalConfig (com.baomidou.mybatisplus.core.config.GlobalConfig)1 MybatisMapWrapperFactory (com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory)1 LogicDeleteByIdWithFill (com.baomidou.mybatisplus.extension.injector.methods.LogicDeleteByIdWithFill)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 DeleteAll (com.baomidou.samples.injector.methods.DeleteAll)1 FindOne (com.baomidou.samples.injector.methods.FindOne)1 DataSource (javax.sql.DataSource)1 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)1 JdbcType (org.apache.ibatis.type.JdbcType)1