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 32 druid:
33 33 # 主库数据源
34 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 37 username: root
38   - password: root
  38 + password: guzijian
39 39 # 从库数据源
40 40 slave:
41 41 # 从数据源开关/默认关闭
... ...
trash-admin/src/main/resources/application.yml
... ... @@ -58,14 +58,14 @@ token:
58 58 # 令牌有效期(默认30分钟)
59 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 70 # PageHelper分页插件
71 71 pagehelper:
... ...
trash-common/pom.xml
... ... @@ -124,6 +124,12 @@
124 124 <artifactId>esdk-obs-java</artifactId>
125 125 <version>[3.20.6.1,)</version>
126 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 134 </dependencies>
129 135  
... ...
trash-framework/pom.xml
... ... @@ -34,11 +34,13 @@
34 34 <groupId>com.alibaba</groupId>
35 35 <artifactId>druid-spring-boot-starter</artifactId>
36 36 </dependency>
  37 + <!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->
37 38 <dependency>
38 39 <groupId>org.mybatis.spring.boot</groupId>
39 40 <artifactId>mybatis-spring-boot-starter</artifactId>
40   - <version>2.1.2</version>
  41 + <version>2.3.1</version>
41 42 </dependency>
  43 +
42 44 <!-- 验证码 -->
43 45 <dependency>
44 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 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 63 \ No newline at end of file
... ...
trash-garbage/pom.xml
... ... @@ -8,26 +8,17 @@
8 8 <version>3.2.0</version>
9 9 </parent>
10 10 <modelVersion>4.0.0</modelVersion>
11   -
12 11 <artifactId>trash-garbage</artifactId>
13   -
14 12 <properties>
15 13 <maven.compiler.source>8</maven.compiler.source>
16 14 <maven.compiler.target>8</maven.compiler.target>
17 15 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18 16 </properties>
19   -
20 17 <dependencies>
21 18 <dependency>
22 19 <groupId>com.trash</groupId>
23 20 <artifactId>trash-common</artifactId>
24 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 22 <dependency>
32 23 <groupId>com.trash</groupId>
33 24 <artifactId>trash-activiti</artifactId>
... ... @@ -56,4 +47,17 @@
56 47 <version>5.3.8</version>
57 48 </dependency>
58 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 63 </project>
60 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 2  
3 3 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4 4 import com.trash.garbage.pojo.domain.GarAddress;
  5 +import org.apache.ibatis.annotations.Mapper;
5 6  
6 7 /**
7 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 10 * @createDate 2023-11-20 16:03:15
11 11 * @Entity garbage.domain.GarUser
12 12 */
13   -@Mapper
14 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 0 \ No newline at end of file