Commit 182428f5bdbed2074dd776e197e96648bd5f3e42

Authored by guzijian
1 parent dc87f013

ci: 整合mybatis plus 升级原先mybatis依赖

trash-admin/src/main/resources/application-dev.yml
@@ -32,10 +32,10 @@ spring: @@ -32,10 +32,10 @@ spring:
32 druid: 32 druid:
33 # 主库数据源 33 # 主库数据源
34 master: 34 master:
35 - #url: jdbc:mysql://localhost:3306/trash?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true  
36 - url: jdbc:mysql://192.168.168.141:3306/trash?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true 35 + url: jdbc:mysql://localhost:3306/trash?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true
  36 +# url: jdbc:mysql://192.168.168.141:3306/trash?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true
37 username: root 37 username: root
38 - password: root 38 + password: guzijian
39 # 从库数据源 39 # 从库数据源
40 slave: 40 slave:
41 # 从数据源开关/默认关闭 41 # 从数据源开关/默认关闭
trash-admin/src/main/resources/application.yml
@@ -58,14 +58,14 @@ token: @@ -58,14 +58,14 @@ token:
58 # 令牌有效期(默认30分钟) 58 # 令牌有效期(默认30分钟)
59 expireTime: 120 59 expireTime: 120
60 60
61 -# MyBatis配置  
62 -mybatis:  
63 - # 搜索指定包别名  
64 - typeAliasesPackage: com.trash.**.domain  
65 - # 配置mapper的扫描,找到所有的mapper.xml映射文件  
66 - mapperLocations: classpath*:mapper/**/*Mapper.xml  
67 - # 加载全局的配置文件  
68 - configLocation: classpath:mybatis/mybatis-config.xml 61 +# MyBatis Plus配置
  62 +mybatis-plus:
  63 + # 搜索指定包别名
  64 + typeAliasesPackage: com.trash.**.domain
  65 + # 配置mapper的扫描,找到所有的mapper.xml映射文件
  66 + mapperLocations: classpath*:mapper/**/*Mapper.xml
  67 + # 加载全局的配置文件
  68 + configLocation: classpath:mybatis/mybatis-config.xml
69 69
70 # PageHelper分页插件 70 # PageHelper分页插件
71 pagehelper: 71 pagehelper:
trash-common/pom.xml
@@ -124,6 +124,12 @@ @@ -124,6 +124,12 @@
124 <artifactId>esdk-obs-java</artifactId> 124 <artifactId>esdk-obs-java</artifactId>
125 <version>[3.20.6.1,)</version> 125 <version>[3.20.6.1,)</version>
126 </dependency> 126 </dependency>
  127 + <!-- mybatis-plus 增强CRUD -->
  128 + <dependency>
  129 + <groupId>com.baomidou</groupId>
  130 + <artifactId>mybatis-plus-boot-starter</artifactId>
  131 + <version>3.4.1</version>
  132 + </dependency>
127 133
128 </dependencies> 134 </dependencies>
129 135
trash-framework/pom.xml
@@ -34,11 +34,13 @@ @@ -34,11 +34,13 @@
34 <groupId>com.alibaba</groupId> 34 <groupId>com.alibaba</groupId>
35 <artifactId>druid-spring-boot-starter</artifactId> 35 <artifactId>druid-spring-boot-starter</artifactId>
36 </dependency> 36 </dependency>
  37 + <!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->
37 <dependency> 38 <dependency>
38 <groupId>org.mybatis.spring.boot</groupId> 39 <groupId>org.mybatis.spring.boot</groupId>
39 <artifactId>mybatis-spring-boot-starter</artifactId> 40 <artifactId>mybatis-spring-boot-starter</artifactId>
40 - <version>2.1.2</version> 41 + <version>2.3.1</version>
41 </dependency> 42 </dependency>
  43 +
42 <!-- 验证码 --> 44 <!-- 验证码 -->
43 <dependency> 45 <dependency>
44 <groupId>com.github.penggle</groupId> 46 <groupId>com.github.penggle</groupId>
trash-framework/src/main/java/com/trash/framework/config/MyBatisConfig.java deleted 100644 → 0
1 -package com.trash.framework.config;  
2 -  
3 -import java.io.IOException;  
4 -import java.util.ArrayList;  
5 -import java.util.HashSet;  
6 -import java.util.List;  
7 -import javax.sql.DataSource;  
8 -import org.apache.ibatis.io.VFS;  
9 -import org.apache.ibatis.session.SqlSessionFactory;  
10 -import org.mybatis.spring.SqlSessionFactoryBean;  
11 -import org.mybatis.spring.boot.autoconfigure.SpringBootVFS;  
12 -import org.springframework.beans.factory.annotation.Autowired;  
13 -import org.springframework.context.annotation.Bean;  
14 -import org.springframework.context.annotation.Configuration;  
15 -import org.springframework.core.env.Environment;  
16 -import org.springframework.core.io.DefaultResourceLoader;  
17 -import org.springframework.core.io.Resource;  
18 -import org.springframework.core.io.support.PathMatchingResourcePatternResolver;  
19 -import org.springframework.core.io.support.ResourcePatternResolver;  
20 -import org.springframework.core.type.classreading.CachingMetadataReaderFactory;  
21 -import org.springframework.core.type.classreading.MetadataReader;  
22 -import org.springframework.core.type.classreading.MetadataReaderFactory;  
23 -import org.springframework.util.ClassUtils;  
24 -  
25 -/**  
26 - * Mybatis支持*匹配扫描包  
27 - *  
28 - * @author trash  
29 - */  
30 -@Configuration  
31 -public class MyBatisConfig  
32 -{  
33 - @Autowired  
34 - private Environment env;  
35 -  
36 - static final String DEFAULT_RESOURCE_PATTERN = "**/*.class";  
37 -  
38 - public static String setTypeAliasesPackage(String typeAliasesPackage)  
39 - {  
40 - ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();  
41 - MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver);  
42 - List<String> allResult = new ArrayList<String>();  
43 - try  
44 - {  
45 - for (String aliasesPackage : typeAliasesPackage.split(","))  
46 - {  
47 - List<String> result = new ArrayList<String>();  
48 - aliasesPackage = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX  
49 - + ClassUtils.convertClassNameToResourcePath(aliasesPackage.trim()) + "/" + DEFAULT_RESOURCE_PATTERN;  
50 - Resource[] resources = resolver.getResources(aliasesPackage);  
51 - if (resources != null && resources.length > 0)  
52 - {  
53 - MetadataReader metadataReader = null;  
54 - for (Resource resource : resources)  
55 - {  
56 - if (resource.isReadable())  
57 - {  
58 - metadataReader = metadataReaderFactory.getMetadataReader(resource);  
59 - try  
60 - {  
61 - result.add(Class.forName(metadataReader.getClassMetadata().getClassName()).getPackage().getName());  
62 - }  
63 - catch (ClassNotFoundException e)  
64 - {  
65 - e.printStackTrace();  
66 - }  
67 - }  
68 - }  
69 - }  
70 - if (result.size() > 0)  
71 - {  
72 - HashSet<String> hashResult = new HashSet<String>(result);  
73 - allResult.addAll(hashResult);  
74 - }  
75 - }  
76 - if (allResult.size() > 0)  
77 - {  
78 - typeAliasesPackage = String.join(",", allResult.toArray(new String[0]));  
79 - }  
80 - else  
81 - {  
82 - throw new RuntimeException("mybatis typeAliasesPackage 路径扫描错误,参数typeAliasesPackage:" + typeAliasesPackage + "未找到任何包");  
83 - }  
84 - }  
85 - catch (IOException e)  
86 - {  
87 - e.printStackTrace();  
88 - }  
89 - return typeAliasesPackage;  
90 - }  
91 -  
92 - @Bean  
93 - public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception  
94 - {  
95 - String typeAliasesPackage = env.getProperty("mybatis.typeAliasesPackage");  
96 - String mapperLocations = env.getProperty("mybatis.mapperLocations");  
97 - String configLocation = env.getProperty("mybatis.configLocation");  
98 - typeAliasesPackage = setTypeAliasesPackage(typeAliasesPackage);  
99 - VFS.addImplClass(SpringBootVFS.class);  
100 -  
101 - final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();  
102 - sessionFactory.setDataSource(dataSource);  
103 - sessionFactory.setTypeAliasesPackage(typeAliasesPackage);  
104 - sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocations));  
105 - sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation));  
106 - return sessionFactory.getObject();  
107 - }  
108 -}  
109 \ No newline at end of file 0 \ No newline at end of file
trash-framework/src/main/java/com/trash/framework/config/MybatisPlusConfig.java 0 → 100644
  1 +package com.trash.framework.config;
  2 +
  3 +import com.baomidou.mybatisplus.annotation.DbType;
  4 +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
  5 +import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
  6 +import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
  7 +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
  8 +import org.springframework.context.annotation.Bean;
  9 +import org.springframework.context.annotation.Configuration;
  10 +import org.springframework.transaction.annotation.EnableTransactionManagement;
  11 +
  12 +/**
  13 + * Mybatis Plus 配置
  14 + *
  15 + * @author ruoyi
  16 + */
  17 +@EnableTransactionManagement(proxyTargetClass = true)
  18 +@Configuration
  19 +public class MybatisPlusConfig
  20 +{
  21 + @Bean
  22 + public MybatisPlusInterceptor mybatisPlusInterceptor()
  23 + {
  24 + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
  25 + // 分页插件
  26 + interceptor.addInnerInterceptor(paginationInnerInterceptor());
  27 + // 乐观锁插件
  28 + interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor());
  29 + // 阻断插件
  30 + interceptor.addInnerInterceptor(blockAttackInnerInterceptor());
  31 + return interceptor;
  32 + }
  33 +
  34 + /**
  35 + * 分页插件,自动识别数据库类型 https://baomidou.com/guide/interceptor-pagination.html
  36 + */
  37 + public PaginationInnerInterceptor paginationInnerInterceptor()
  38 + {
  39 + PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
  40 + // 设置数据库类型为mysql
  41 + paginationInnerInterceptor.setDbType(DbType.MYSQL);
  42 + // 设置最大单页限制数量,默认 500 条,-1 不受限制
  43 + paginationInnerInterceptor.setMaxLimit(-1L);
  44 + return paginationInnerInterceptor;
  45 + }
  46 +
  47 + /**
  48 + * 乐观锁插件 https://baomidou.com/guide/interceptor-optimistic-locker.html
  49 + */
  50 + public OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor()
  51 + {
  52 + return new OptimisticLockerInnerInterceptor();
  53 + }
  54 +
  55 + /**
  56 + * 如果是对全表的删除或更新操作,就会终止该操作 https://baomidou.com/guide/interceptor-block-attack.html
  57 + */
  58 + public BlockAttackInnerInterceptor blockAttackInnerInterceptor()
  59 + {
  60 + return new BlockAttackInnerInterceptor();
  61 + }
  62 +}
0 \ No newline at end of file 63 \ No newline at end of file
trash-garbage/pom.xml
@@ -8,26 +8,17 @@ @@ -8,26 +8,17 @@
8 <version>3.2.0</version> 8 <version>3.2.0</version>
9 </parent> 9 </parent>
10 <modelVersion>4.0.0</modelVersion> 10 <modelVersion>4.0.0</modelVersion>
11 -  
12 <artifactId>trash-garbage</artifactId> 11 <artifactId>trash-garbage</artifactId>
13 -  
14 <properties> 12 <properties>
15 <maven.compiler.source>8</maven.compiler.source> 13 <maven.compiler.source>8</maven.compiler.source>
16 <maven.compiler.target>8</maven.compiler.target> 14 <maven.compiler.target>8</maven.compiler.target>
17 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 15 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18 </properties> 16 </properties>
19 -  
20 <dependencies> 17 <dependencies>
21 <dependency> 18 <dependency>
22 <groupId>com.trash</groupId> 19 <groupId>com.trash</groupId>
23 <artifactId>trash-common</artifactId> 20 <artifactId>trash-common</artifactId>
24 </dependency> 21 </dependency>
25 - <!-- mybatis plus-->  
26 - <dependency>  
27 - <groupId>com.baomidou</groupId>  
28 - <artifactId>mybatis-plus-boot-starter</artifactId>  
29 - <version>3.5.4.1</version>  
30 - </dependency>  
31 <dependency> 22 <dependency>
32 <groupId>com.trash</groupId> 23 <groupId>com.trash</groupId>
33 <artifactId>trash-activiti</artifactId> 24 <artifactId>trash-activiti</artifactId>
@@ -56,4 +47,17 @@ @@ -56,4 +47,17 @@
56 <version>5.3.8</version> 47 <version>5.3.8</version>
57 </dependency> 48 </dependency>
58 </dependencies> 49 </dependencies>
  50 + <!-- 项目打包时会将java目录中的*.xml文件也进行打包 -->
  51 + <build>
  52 + <resources>
  53 + <resource>
  54 + <directory>src/main/java</directory>
  55 + <includes>
  56 + <include>**/*.xml</include>
  57 + </includes>
  58 + <filtering>false</filtering>
  59 + </resource>
  60 + </resources>
  61 + </build>
  62 +
59 </project> 63 </project>
60 \ No newline at end of file 64 \ No newline at end of file
trash-garbage/src/main/java/com/trash/garbage/config/MybatisConfig.java deleted 100644 → 0
1 -package com.trash.garbage.config;  
2 -  
3 -import com.baomidou.mybatisplus.annotation.DbType;  
4 -import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;  
5 -import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;  
6 -import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;  
7 -import org.mybatis.spring.annotation.MapperScan;  
8 -import org.springframework.context.annotation.Bean;  
9 -import org.springframework.context.annotation.Configuration;  
10 -  
11 -  
12 -/**  
13 - * @author 20412  
14 - */  
15 -@Configuration  
16 -@MapperScan("com.trash.garbage.mapper")  
17 -public class MybatisConfig {  
18 -  
19 - @Bean  
20 - public MybatisPlusInterceptor mybatisPlusInterceptor() {  
21 - MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();  
22 - interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));  
23 - return interceptor;  
24 - }  
25 -}  
trash-garbage/src/main/java/com/trash/garbage/mapper/GarAddressMapper.java
@@ -2,6 +2,7 @@ package com.trash.garbage.mapper; @@ -2,6 +2,7 @@ package com.trash.garbage.mapper;
2 2
3 import com.baomidou.mybatisplus.core.mapper.BaseMapper; 3 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4 import com.trash.garbage.pojo.domain.GarAddress; 4 import com.trash.garbage.pojo.domain.GarAddress;
  5 +import org.apache.ibatis.annotations.Mapper;
5 6
6 /** 7 /**
7 * @author 20412 8 * @author 20412
trash-garbage/src/main/java/com/trash/garbage/mapper/GarUserMapper.java
@@ -10,7 +10,6 @@ import org.apache.ibatis.annotations.Mapper; @@ -10,7 +10,6 @@ import org.apache.ibatis.annotations.Mapper;
10 * @createDate 2023-11-20 16:03:15 10 * @createDate 2023-11-20 16:03:15
11 * @Entity garbage.domain.GarUser 11 * @Entity garbage.domain.GarUser
12 */ 12 */
13 -@Mapper  
14 public interface GarUserMapper extends BaseMapper<GarUser> { 13 public interface GarUserMapper extends BaseMapper<GarUser> {
15 14
16 } 15 }
trash-garbage/src/main/resources/application.yml deleted 100644 → 0
1 -# mybaits 配置  
2 -mybatis-plus:  
3 - global-config:  
4 - # 指定逻辑删除含义  
5 - db-config:  
6 - logic-delete-value: 1  
7 - logic-not-delete-value: 0  
8 - configuration:  
9 - # 日志打印sql  
10 - log-impl: org.apache.ibatis.logging.stdout.StdOutImpl  
11 \ No newline at end of file 0 \ No newline at end of file