From 32bfe334c0be11152b1789ddcc2d54b26daf342b Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期四, 21 十月 2021 18:41:56 +0800 Subject: [PATCH] update 整理删除无用注释 保证代码整洁 --- ruoyi-framework/src/main/java/com/ruoyi/framework/config/MybatisPlusConfig.java | 112 ++++++++++++++++++++++++++++++------------------------- 1 files changed, 61 insertions(+), 51 deletions(-) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/MybatisPlusConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/MybatisPlusConfig.java index 5073512..db81b74 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/MybatisPlusConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/MybatisPlusConfig.java @@ -1,92 +1,102 @@ package com.ruoyi.framework.config; -import com.baomidou.mybatisplus.annotation.DbType; -import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer; -import com.baomidou.mybatisplus.core.incrementer.IKeyGenerator; -import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator; -import com.baomidou.mybatisplus.extension.incrementer.H2KeyGenerator; -import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor; -import com.baomidou.mybatisplus.extension.plugins.inner.IllegalSQLInnerInterceptor; +import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; +import com.baomidou.mybatisplus.core.injector.AbstractMethod; +import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector; +import com.baomidou.mybatisplus.core.injector.ISqlInjector; +import com.baomidou.mybatisplus.core.metadata.TableInfo; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; -import com.baomidou.mybatisplus.extension.plugins.pagination.optimize.JsqlParserCountOptimize; +import com.ruoyi.common.core.mybatisplus.methods.InsertAll; +import com.ruoyi.framework.handler.CreateAndUpdateMetaObjectHandler; +import org.mybatis.spring.annotation.MapperScan; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.transaction.annotation.EnableTransactionManagement; +import java.util.List; + +/** + * mybatis-plus閰嶇疆绫�(涓嬫柟娉ㄩ噴鏈夋彃浠朵粙缁�) + * + * @author Lion Li + */ @EnableTransactionManagement(proxyTargetClass = true) @Configuration +@MapperScan("${mybatis-plus.mapperPackage}") public class MybatisPlusConfig { + + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + // 鍒嗛〉鎻掍欢 + interceptor.addInnerInterceptor(paginationInnerInterceptor()); + // 涔愯閿佹彃浠� + interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor()); + return interceptor; + } /** * 鍒嗛〉鎻掍欢锛岃嚜鍔ㄨ瘑鍒暟鎹簱绫诲瀷 */ - @Bean public PaginationInnerInterceptor paginationInnerInterceptor() { PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(); - // 璁剧疆鏁版嵁搴撶被鍨嬩负mysql - paginationInnerInterceptor.setDbType(DbType.MYSQL); // 璁剧疆鏈�澶у崟椤甸檺鍒舵暟閲忥紝榛樿 500 鏉★紝-1 涓嶅彈闄愬埗 paginationInnerInterceptor.setMaxLimit(-1L); + // 鍒嗛〉鍚堢悊鍖� + paginationInnerInterceptor.setOverflow(true); return paginationInnerInterceptor; - } - - /** - * 鏂扮殑鍒嗛〉鎻掍欢,涓�缂撳拰浜岀紦閬靛惊mybatis鐨勮鍒�,闇�瑕佽缃� MybatisConfiguration#useDeprecatedExecutor = false 閬垮厤缂撳瓨鍑虹幇闂(璇ュ睘鎬т細鍦ㄦ棫鎻掍欢绉婚櫎鍚庝竴鍚岀Щ闄�) - */ - @Bean - public ConfigurationCustomizer configurationCustomizer() { - return configuration -> configuration.setUseDeprecatedExecutor(false); } /** * 涔愯閿佹彃浠� */ - @Bean public OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor() { return new OptimisticLockerInnerInterceptor(); } /** - * 濡傛灉鏄鍏ㄨ〃鐨勫垹闄ゆ垨鏇存柊鎿嶄綔锛屽氨浼氱粓姝㈣鎿嶄綔 + * 鍏冨璞″瓧娈靛~鍏呮帶鍒跺櫒 */ @Bean - public BlockAttackInnerInterceptor blockAttackInnerInterceptor() { - return new BlockAttackInnerInterceptor(); + public MetaObjectHandler metaObjectHandler() { + return new CreateAndUpdateMetaObjectHandler(); } /** - * sql鎬ц兘瑙勮寖鎻掍欢(鍨冨溇SQL鎷︽埅) - * 濡傛湁闇�瑕佸彲浠ュ惎鐢� + * sql娉ㄥ叆鍣ㄩ厤缃� */ -// @Bean -// public IllegalSQLInnerInterceptor illegalSQLInnerInterceptor() { -// return new IllegalSQLInnerInterceptor(); -// } + @Bean + public ISqlInjector sqlInjector() { + return new DefaultSqlInjector() { + @Override + public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) { + List<AbstractMethod> methodList = super.getMethodList(mapperClass, tableInfo); + methodList.add(new InsertAll()); + return methodList; + } + }; + } /** - * Sequence涓婚敭绛栫暐 IdType.INPUT 鏃朵娇鐢� - * 鍐呯疆鏀寔锛� - * - * DB2KeyGenerator - * H2KeyGenerator - * KingbaseKeyGenerator - * OracleKeyGenerator - * PostgreKeyGenerator + * PaginationInnerInterceptor 鍒嗛〉鎻掍欢锛岃嚜鍔ㄨ瘑鍒暟鎹簱绫诲瀷 + * https://baomidou.com/guide/interceptor-pagination.html + * OptimisticLockerInnerInterceptor 涔愯閿佹彃浠� + * https://baomidou.com/guide/interceptor-optimistic-locker.html + * MetaObjectHandler 鍏冨璞″瓧娈靛~鍏呮帶鍒跺櫒 + * https://baomidou.com/guide/auto-fill-metainfo.html + * ISqlInjector sql娉ㄥ叆鍣� + * https://baomidou.com/guide/sql-injector.html + * BlockAttackInnerInterceptor 濡傛灉鏄鍏ㄨ〃鐨勫垹闄ゆ垨鏇存柊鎿嶄綔锛屽氨浼氱粓姝㈣鎿嶄綔 + * https://baomidou.com/guide/interceptor-block-attack.html + * IllegalSQLInnerInterceptor sql鎬ц兘瑙勮寖鎻掍欢(鍨冨溇SQL鎷︽埅) + * IdentifierGenerator 鑷畾涔変富閿瓥鐣� + * https://baomidou.com/guide/id-generator.html + * TenantLineInnerInterceptor 澶氱鎴锋彃浠� + * https://baomidou.com/guide/interceptor-tenant-line.html + * DynamicTableNameInnerInterceptor 鍔ㄦ�佽〃鍚嶆彃浠� + * https://baomidou.com/guide/interceptor-dynamic-table-name.html */ -// @Bean -// public IKeyGenerator keyGenerator() { -// return new H2KeyGenerator(); -// } - - - /** - * 鑷畾涔変富閿瓥鐣� - */ -// @Bean -// public IdentifierGenerator idGenerator() { -// return new CustomIdGenerator(); -// } - } -- Gitblit v1.9.3