|
@@ -0,0 +1,63 @@
|
|
|
|
|
+package top.haijunit.mybatis.config;
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.core.net.NetUtil;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
|
|
|
|
+import org.mybatis.spring.annotation.MapperScan;
|
|
|
|
|
+import org.springframework.boot.autoconfigure.AutoConfiguration;
|
|
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
|
|
+import org.springframework.context.annotation.PropertySource;
|
|
|
|
|
+import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|
|
|
|
+import top.haijunit.common.factory.YmlPropertySourceFactory;
|
|
|
|
|
+import top.haijunit.mybatis.handler.InjectionMetaObjectHandler;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @author zhanghaijun
|
|
|
|
|
+ * @date 2023/11/3 16:36
|
|
|
|
|
+ * @description Mybatis配置
|
|
|
|
|
+ */
|
|
|
|
|
+@EnableTransactionManagement(proxyTargetClass = true)
|
|
|
|
|
+@AutoConfiguration
|
|
|
|
|
+@MapperScan("${mybatis-plus.mapperPackage}")
|
|
|
|
|
+@PropertySource(value = "classpath:common-mybatis.yml", factory = YmlPropertySourceFactory.class)
|
|
|
|
|
+public class MybatisPlusConfig {
|
|
|
|
|
+
|
|
|
|
|
+ @Bean
|
|
|
|
|
+ public MetaObjectHandler metaObjectHandler() {
|
|
|
|
|
+ return new InjectionMetaObjectHandler();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Bean
|
|
|
|
|
+ public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
|
|
|
|
+ MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
|
|
|
|
+ // 分页插件
|
|
|
|
|
+ interceptor.addInnerInterceptor(paginationInnerInterceptor());
|
|
|
|
|
+ return interceptor;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 使用网卡信息绑定雪花生成器
|
|
|
|
|
+ * 防止集群雪花ID重复
|
|
|
|
|
+ */
|
|
|
|
|
+ @Bean
|
|
|
|
|
+ public IdentifierGenerator idGenerator() {
|
|
|
|
|
+ return new DefaultIdentifierGenerator(NetUtil.getLocalhost());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 分页插件,自动识别数据库类型
|
|
|
|
|
+ */
|
|
|
|
|
+ public PaginationInnerInterceptor paginationInnerInterceptor() {
|
|
|
|
|
+ PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
|
|
|
|
|
+ // 设置最大单页限制数量,默认 500 条,-1 不受限制
|
|
|
|
|
+ paginationInnerInterceptor.setMaxLimit(-1L);
|
|
|
|
|
+ // 分页合理化
|
|
|
|
|
+ paginationInnerInterceptor.setOverflow(true);
|
|
|
|
|
+ return paginationInnerInterceptor;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|