Search in sources :

Example 6 with AbstractMethod

use of com.baomidou.mybatisplus.core.injector.AbstractMethod 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 7 with AbstractMethod

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

the class MyLogicSqlInjector method getMethodList.

/**
 * 如果只需增加方法,保留MP自带方法
 * 可以super.getMethodList() 再add
 * @return
 */
@Override
public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
    List<AbstractMethod> methodList = super.getMethodList(mapperClass, tableInfo);
    methodList.add(new DeleteAll());
    methodList.add(new MyInsertAll());
    methodList.add(new MysqlInsertAllBatch());
    methodList.add(new SelectById());
    return methodList;
}
Also used : DeleteAll(com.baomidou.mybatisplus.samples.deluxe.methods.DeleteAll) AbstractMethod(com.baomidou.mybatisplus.core.injector.AbstractMethod) SelectById(com.baomidou.mybatisplus.core.injector.methods.SelectById) MyInsertAll(com.baomidou.mybatisplus.samples.deluxe.methods.MyInsertAll) MysqlInsertAllBatch(com.baomidou.mybatisplus.samples.deluxe.methods.MysqlInsertAllBatch)

Example 8 with AbstractMethod

use of com.baomidou.mybatisplus.core.injector.AbstractMethod 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)

Example 9 with AbstractMethod

use of com.baomidou.mybatisplus.core.injector.AbstractMethod in project tutorials-java by Artister.

the class MySqlInjector method getMethodList.

@Override
public List<AbstractMethod> getMethodList(Class<?> mapperClass) {
    List<AbstractMethod> methodList = super.getMethodList(mapperClass);
    // 增加自定义方法
    methodList.add(new DeleteAll());
    return methodList;
}
Also used : DeleteAll(com.baomidou.samples.injector.methods.DeleteAll) AbstractMethod(com.baomidou.mybatisplus.core.injector.AbstractMethod)

Example 10 with AbstractMethod

use of com.baomidou.mybatisplus.core.injector.AbstractMethod in project tutorials-java by Artister.

the class MyLogicSqlInjector method getMethodList.

/**
 * 如果只需增加方法,保留MP自带方法
 * 可以super.getMethodList() 再add
 * @return
 */
@Override
public List<AbstractMethod> getMethodList(Class<?> mapperClass) {
    List<AbstractMethod> methodList = super.getMethodList(mapperClass);
    methodList.add(new DeleteAll());
    methodList.add(new MyInsertAll());
    methodList.add(new MysqlInsertAllBatch());
    methodList.add(new SelectById());
    return methodList;
}
Also used : DeleteAll(com.baomidou.mybatisplus.samples.deluxe.methods.DeleteAll) AbstractMethod(com.baomidou.mybatisplus.core.injector.AbstractMethod) SelectById(com.baomidou.mybatisplus.core.injector.methods.SelectById) MyInsertAll(com.baomidou.mybatisplus.samples.deluxe.methods.MyInsertAll) MysqlInsertAllBatch(com.baomidou.mybatisplus.samples.deluxe.methods.MysqlInsertAllBatch)

Aggregations

AbstractMethod (com.baomidou.mybatisplus.core.injector.AbstractMethod)11 FieldFill (com.baomidou.mybatisplus.annotation.FieldFill)6 List (java.util.List)6 InsertBatchSomeColumn (com.baomidou.mybatisplus.extension.injector.methods.InsertBatchSomeColumn)5 DefaultSqlInjector (com.baomidou.mybatisplus.core.injector.DefaultSqlInjector)4 TableInfo (com.baomidou.mybatisplus.core.metadata.TableInfo)4 MybatisPlusInterceptor (com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor)3 PaginationInnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor)3 Bean (org.springframework.context.annotation.Bean)3 Configuration (org.springframework.context.annotation.Configuration)3 ArrayUtil (cn.hutool.core.util.ArrayUtil)2 ISqlInjector (com.baomidou.mybatisplus.core.injector.ISqlInjector)2 SelectById (com.baomidou.mybatisplus.core.injector.methods.SelectById)2 AlwaysUpdateSomeColumnById (com.baomidou.mybatisplus.extension.injector.methods.AlwaysUpdateSomeColumnById)2 DeleteAll (com.baomidou.mybatisplus.samples.deluxe.methods.DeleteAll)2 MyInsertAll (com.baomidou.mybatisplus.samples.deluxe.methods.MyInsertAll)2 MysqlInsertAllBatch (com.baomidou.mybatisplus.samples.deluxe.methods.MysqlInsertAllBatch)2 DeleteAll (com.baomidou.samples.injector.methods.DeleteAll)2 CustomSqlInjector (com.hccake.extend.mybatis.plus.injector.CustomSqlInjector)2 InsertBatchSomeColumnByCollection (com.hccake.extend.mybatis.plus.methods.InsertBatchSomeColumnByCollection)2