Browse Source

策略模式在项目中是怎么用的?

pull/2/head
马府强 1 year ago
parent
commit
fa6392405f
  1. 27
      strategydesign/.gitignore
  2. 181
      strategydesign/pom.xml
  3. 16
      strategydesign/src/main/java/com/woniu/WoNiuApplication.java
  4. 45
      strategydesign/src/main/java/com/woniu/config/MasterDataSourceConfig.java
  5. 48
      strategydesign/src/main/java/com/woniu/config/SlaveDataSourceConfig.java
  6. 8
      strategydesign/src/main/java/com/woniu/constant/Constants.java
  7. 13
      strategydesign/src/main/java/com/woniu/dao/master/MasterUserDao.java
  8. 12
      strategydesign/src/main/java/com/woniu/dao/slave/SlaveUserDao.java
  9. 46
      strategydesign/src/main/java/com/woniu/retry/GuavaRetryTest.java
  10. 34
      strategydesign/src/main/java/com/woniu/service/UserService.java
  11. 34
      strategydesign/src/main/java/com/woniu/strategy/CodeEnum.java
  12. 66
      strategydesign/src/main/java/com/woniu/strategy/SearchTransformService.java
  13. 8
      strategydesign/src/main/java/com/woniu/strategy/TransferService.java
  14. 20
      strategydesign/src/main/java/com/woniu/strategy/service/AgeTransferService.java
  15. 19
      strategydesign/src/main/java/com/woniu/strategy/service/InterestTransferService.java
  16. 18
      strategydesign/src/main/java/com/woniu/strategy/service/UserTransferService.java
  17. 10
      strategydesign/src/main/java/com/woniu/vo/User.java
  18. 52
      strategydesign/src/main/resources/application.properties
  19. 14
      strategydesign/src/main/resources/application.yml
  20. BIN
      strategydesign/src/main/resources/ip2region/ip2region.xdb
  21. 26
      strategydesign/src/main/resources/logback-spring.xml
  22. 12
      strategydesign/src/main/resources/mapper/master/UserDaoMapper.xml
  23. 9
      strategydesign/src/main/resources/mapper/slave/UserDaoMapper.xml
  24. 35
      strategydesign/src/main/resources/mybatis-config.xml
  25. 154
      strategydesign/woniu-web.iml

27
strategydesign/.gitignore

@ -0,0 +1,27 @@
# Created by .ignore support plugin (hsz.mobi)
### Java template
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/.idea/
/target/

181
strategydesign/pom.xml

@ -0,0 +1,181 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.ayi</groupId>
<artifactId>woniu-web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>woniu-web</name>
<description>create by woniu</description>
<packaging>jar</packaging>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.github.rholder</groupId>
<artifactId>guava-retrying</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>29.0-jre</version>
</dependency>
<dependency>
<groupId>org.lionsoul</groupId>
<artifactId>ip2region</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.3.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<!-- <scope>test</scope>-->
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<!-- 集成mybatis -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/druid-spring-boot-starter -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.18</version>
</dependency>
<!--引入阿里巴巴druid连接池-->
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.29</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>runtime-sofa-boot-starter</artifactId>
<version>3.18.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.redisson</groupId>-->
<!-- <artifactId>redisson</artifactId>-->
<!-- <version>3.21.0</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-data-redis</artifactId>-->
<!-- <version>2.1.18.RELEASE</version>-->
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <groupId>ch.qos.logback</groupId>-->
<!-- <artifactId>logback-classic</artifactId>-->
<!-- </exclusion>-->
<!-- <exclusion>-->
<!-- <groupId>org.slf4j</groupId>-->
<!-- <artifactId>jul-to-slf4j</artifactId>-->
<!-- </exclusion>-->
<!-- <exclusion>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-logging</artifactId>-->
<!-- </exclusion>-->
<!-- <exclusion>-->
<!-- <artifactId>lettuce-core</artifactId>-->
<!-- <groupId>io.lettuce</groupId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<!-- </dependency>-->
<!-- &lt;!&ndash; https://mvnrepository.com/artifact/redis.clients/jedis &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>redis.clients</groupId>-->
<!-- <artifactId>jedis</artifactId>-->
<!-- <version>4.4.3</version>-->
<!-- </dependency>-->
<!-- 不可升级,3.x以上最低jdk11-->
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.9.3</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.76</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.0.5</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

16
strategydesign/src/main/java/com/woniu/WoNiuApplication.java

@ -0,0 +1,16 @@
package com.woniu;
import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication(exclude = MybatisAutoConfiguration.class)
public class WoNiuApplication {
public static void main(String[] args) {
SpringApplication.run(WoNiuApplication.class, args);
}
}

45
strategydesign/src/main/java/com/woniu/config/MasterDataSourceConfig.java

@ -0,0 +1,45 @@
package com.woniu.config;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import javax.sql.DataSource;
/**
* 优雅的实现 mybatis多数据源
* 在新增数据时除了给自己的库保留一份还需要同步到别人的库
*/
@Slf4j
@Configuration
@MapperScan(basePackages = {"com.woniu.dao.master"},
sqlSessionFactoryRef = "MasterSqlSessionFactory")
public class MasterDataSourceConfig {
@Bean(name = "MasterDataSource")
@Qualifier("MasterDataSource")
@ConfigurationProperties(prefix = "spring.datasource.master")
public DataSource clickHouseDataSource() {
return DruidDataSourceBuilder.create().build();
}
@Bean(name = "MasterSqlSessionFactory")
public SqlSessionFactory getSqlSessionFactory(@Qualifier("MasterDataSource") DataSource dataSource) throws Exception {
SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
sessionFactoryBean.setDataSource(dataSource);
sessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver()
.getResources("classpath*:mapper/master/*.xml"));
log.info("------------------------------------------MasterDataSource 配置成功");
return sessionFactoryBean.getObject();
}
}

48
strategydesign/src/main/java/com/woniu/config/SlaveDataSourceConfig.java

@ -0,0 +1,48 @@
package com.woniu.config;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource;
/**
* 优雅的实现 mybatis多数据源
* 在实际开发中会遇到多数据源的场景比如说在新增数据时除了给自己的库保留一份还需要同步到别人的库
*/
@Slf4j
@Configuration
@MapperScan(basePackages = {"com.woniu.dao.slave"},
sqlSessionFactoryRef = "SlaveSqlSessionFactory")
public class SlaveDataSourceConfig {
@Bean(name = "SlaveDataSource")
@Qualifier("SlaveDataSource")
@ConfigurationProperties(prefix = "spring.datasource.slave")
public DataSource clickHouseDataSource() {
return DruidDataSourceBuilder.create().build();
}
@Bean(name = "SlaveSqlSessionFactory")
public SqlSessionFactory getSqlSessionFactory(@Qualifier("SlaveDataSource") DataSource dataSource) throws Exception {
SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
sessionFactoryBean.setDataSource(dataSource);
sessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver()
.getResources("classpath*:mapper/slave/*.xml"));
log.info("------------------------------------------SlaveDataSource 配置成功");
return sessionFactoryBean.getObject();
}
}

8
strategydesign/src/main/java/com/woniu/constant/Constants.java

@ -0,0 +1,8 @@
package com.woniu.constant;
public class Constants {
public static String ADDRESS = "";
}

13
strategydesign/src/main/java/com/woniu/dao/master/MasterUserDao.java

@ -0,0 +1,13 @@
package com.woniu.dao.master;
import com.woniu.vo.User;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface MasterUserDao {
int insertUser(User user);
}

12
strategydesign/src/main/java/com/woniu/dao/slave/SlaveUserDao.java

@ -0,0 +1,12 @@
package com.woniu.dao.slave;
import com.woniu.vo.User;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface SlaveUserDao {
int insertUser(User user);
}

46
strategydesign/src/main/java/com/woniu/retry/GuavaRetryTest.java

@ -0,0 +1,46 @@
package com.woniu.retry;
import com.github.rholder.retry.*;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
//Guava Retry重试原来这么简单!根据返回值判断是否需要重试!
@Slf4j
public class GuavaRetryTest {
private Integer num = 1;
@Test
public void guavaRetry() {
Retryer<String> retryer = RetryerBuilder.<String>newBuilder()
//无论出现什么异常,都进行重试
.retryIfException()
//返回结果为 error时,进行重试
.retryIfResult(result -> Objects.equals(result, "error"))
//重试等待策略:等待 2s 后再进行重试
.withWaitStrategy(WaitStrategies.fixedWait(2, TimeUnit.SECONDS))
//重试停止策略:重试达到 3 次
.withStopStrategy(StopStrategies.stopAfterAttempt(3))
.withRetryListener(new RetryListener() {
@Override
public <V> void onRetry(Attempt<V> attempt) {
System.out.println("RetryListener: 第" + attempt.getAttemptNumber() + "次调用");
}
})
.build();
try {
retryer.call(() -> testGuavaRetry());
} catch (Exception e) {
e.printStackTrace();
}
}
private String testGuavaRetry() {
log.info("重试次数:{}", num++);
return "error";
}
}

34
strategydesign/src/main/java/com/woniu/service/UserService.java

@ -0,0 +1,34 @@
package com.woniu.service;
import com.woniu.dao.master.MasterUserDao;
import com.woniu.dao.slave.SlaveUserDao;
import com.woniu.vo.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@SpringBootTest
@RunWith(SpringRunner.class)
public class UserService {
@Autowired
private MasterUserDao masterUserDao;
@Autowired
private SlaveUserDao slaveUserDao;
@Test
public void testUser() {
User user = new User();
user.setId(1l);
user.setSex(1);
user.setName("蜗牛");
masterUserDao.insertUser(user);
slaveUserDao.insertUser(user);
}
}

34
strategydesign/src/main/java/com/woniu/strategy/CodeEnum.java

@ -0,0 +1,34 @@
package com.woniu.strategy;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
public enum CodeEnum {
USER("user"),
AGE("age"),
INTEREST("interest"),
;
private String code;
public String getCode() {
return code;
}
CodeEnum(String code) {
this.code = code;
}
private static final Map<String, CodeEnum> map = Arrays.stream(CodeEnum.values()).collect(Collectors.toMap(CodeEnum::getCode, Function.identity()));
public static CodeEnum of(String code) {
return map.get(code);
}
}

66
strategydesign/src/main/java/com/woniu/strategy/SearchTransformService.java

@ -0,0 +1,66 @@
package com.woniu.strategy;
import cn.hutool.core.lang.Assert;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
//知道策略模式!但不会在项目里使用?
@Service
public class SearchTransformService implements InitializingBean {
// @Autowired
// private UserTransferService userTransferService;
// @Autowired
// private AgeTransferService ageTransferService;
// @Autowired
// private InterestTransferService interestTransferService;
/**
* 根据不同的编码进行转换
* @param code
* @return
*/
public String transform2(String code) {
// if(code.equals("user")){
// return userTransferService.transfer();
// }else if(code.equals("age")){
// return ageTransferService.transfer();
// }else if(code.equals("interest")){
// return interestTransferService.transfer();
// }
return "";
}
@Autowired
private List<TransferService> transferServiceList;
private Map<CodeEnum, TransferService> transferServiceMap;
@Override
// 项目启动时将实现类放入到map中去
public void afterPropertiesSet() throws Exception {
transferServiceMap = transferServiceList
.stream()
.collect(Collectors.toMap(TransferService::transCode, Function.identity()));
}
/**
* 根据不同的编码进行转换
* @param code
* @return
*/
public String transform(String code) {
TransferService transferService = transferServiceMap.get(CodeEnum.of(code));
Assert.notNull(transferService, "找不到对应的转换器");
return transferService.transfer();
}
}

8
strategydesign/src/main/java/com/woniu/strategy/TransferService.java

@ -0,0 +1,8 @@
package com.woniu.strategy;
public interface TransferService {
String transfer();
CodeEnum transCode();
}

20
strategydesign/src/main/java/com/woniu/strategy/service/AgeTransferService.java

@ -0,0 +1,20 @@
package com.woniu.strategy.service;
import com.woniu.strategy.CodeEnum;
import com.woniu.strategy.TransferService;
import org.springframework.stereotype.Service;
@Service
public class AgeTransferService implements TransferService {
@Override
public String transfer() {
return "age";
}
@Override
public CodeEnum transCode() {
return CodeEnum.AGE;
}
}

19
strategydesign/src/main/java/com/woniu/strategy/service/InterestTransferService.java

@ -0,0 +1,19 @@
package com.woniu.strategy.service;
import com.woniu.strategy.CodeEnum;
import com.woniu.strategy.TransferService;
import org.springframework.stereotype.Service;
@Service
public class InterestTransferService implements TransferService {
@Override
public String transfer() {
return "interest";
}
@Override
public CodeEnum transCode() {
return CodeEnum.INTEREST;
}
}

18
strategydesign/src/main/java/com/woniu/strategy/service/UserTransferService.java

@ -0,0 +1,18 @@
package com.woniu.strategy.service;
import com.woniu.strategy.CodeEnum;
import com.woniu.strategy.TransferService;
import org.springframework.stereotype.Service;
@Service
public class UserTransferService implements TransferService {
@Override
public String transfer() {
return "user";
}
@Override
public CodeEnum transCode() {
return CodeEnum.USER;
}
}

10
strategydesign/src/main/java/com/woniu/vo/User.java

@ -0,0 +1,10 @@
package com.woniu.vo;
import lombok.Data;
@Data
public class User {
private Long id;
private String name;
private Integer sex;
}

52
strategydesign/src/main/resources/application.properties

@ -0,0 +1,52 @@
#
spring.application.name=www
server.port=8081
##1800s
#server.servlet.session.timeout=1800
#spring.jackson.time-zone=GMT+8
#spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
#
##定义数据源
#spring.shardingsphere.datasource.names=m1,m2
#
#spring.shardingsphere.datasource.m1.url=jdbc:mysql://127.0.0.1:3306/test?serverTimezone=GMT%2b8&useUnicode=true&characterEncoding=utf8
#spring.shardingsphere.datasource.m1.username=root
#spring.shardingsphere.datasource.m1.password=123456
#spring.shardingsphere.datasource.m1.driver‐class‐name=com.mysql.cj.jdbc.Driver
#spring.shardingsphere.datasource.m1.type=com.alibaba.druid.pool.DruidDataSource
#
#
#spring.shardingsphere.datasource.m2.url=jdbc:mysql://127.0.0.1:3306/test2?serverTimezone=GMT%2b8&useUnicode=true&characterEncoding=utf8
#spring.shardingsphere.datasource.m2.username=root
#spring.shardingsphere.datasource.m2.password=123456
#spring.shardingsphere.datasource.m2.driver‐class‐name=com.mysql.cj.jdbc.Driver
#spring.shardingsphere.datasource.m2.type=com.alibaba.druid.pool.DruidDataSource
#
## 指定t_user表的数据分布情况,配置数据节点
#spring.shardingsphere.sharding.tables.t_user.actual‐data‐nodes=m$->{1..2}.t_user_$->{1..2}
#
## 指定t_user表的主键生成策略为SNOWFLAKE
#spring.shardingsphere.sharding.tables.t_user.key‐generator.column=id
#spring.shardingsphere.sharding.tables.t_user.key‐generator.type=SNOWFLAKE
#
## 指定t_user表的分库策略,分库策略包括分片键和分片算法
#spring.shardingsphere.sharding.tables.t_user.database-strategy.inline.sharding‐column=sex
#spring.shardingsphere.sharding.tables.t_user.database-strategy.inline.algorithm‐expression=m$->{sex % 2 + 1}
#
#
## 指定t_user表的分表策略,分表策略包括分片键和分片算法
#spring.shardingsphere.sharding.tables.t_user.table‐strategy.inline.sharding‐column=id
#spring.shardingsphere.sharding.tables.t_user.table‐strategy.inline.algorithm‐expression=t_user_$->{id % 2 + 1}
#
#
## 控制台日志配置
#logging.level.root=info
#
## 打开sql输出日志
#spring.shardingsphere.props.sql.show=true
#
##mapper文件扫描路径
#mybatis.mapper-locations=classpath:/mapper/*.xml
#
#
#

14
strategydesign/src/main/resources/application.yml

@ -0,0 +1,14 @@
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
# 主库数据源
master:
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: 123456
slave:
url: jdbc:mysql://localhost:3306/test2?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: 123456

BIN
strategydesign/src/main/resources/ip2region/ip2region.xdb

Binary file not shown.

26
strategydesign/src/main/resources/logback-spring.xml

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- 控制台日志格式 -->
<property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %X{requestId} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
<!-- 控制台日志格式 依赖的渲染类 -->
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
<conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
<!-- 输出到控制台 -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<!-- 配置日志输出格式 -->
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
<!-- 使用的字符集 -->
<charset>UTF-8</charset>
</encoder>
</appender>
<!-- 开启上面的appender -->
<root level="info">
<appender-ref ref="CONSOLE" />
</root>
</configuration>

12
strategydesign/src/main/resources/mapper/master/UserDaoMapper.xml

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.woniu.dao.master.MasterUserDao">
<insert id="insertUser" >
insert into t_user_1(id,name, sex) values (#{id},#{name}, #{sex})
</insert>
</mapper>

9
strategydesign/src/main/resources/mapper/slave/UserDaoMapper.xml

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.woniu.dao.slave.SlaveUserDao">
<insert id="insertUser">
insert into t_user_1(id,name, sex) values (#{id},#{name}, #{sex})
</insert>
</mapper>

35
strategydesign/src/main/resources/mybatis-config.xml

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<!-- 打印sql日志 -->
<setting name="logImpl" value="org.apache.ibatis.logging.stdout.StdOutImpl"/>
</settings>
<plugins>
<plugin interceptor="com.github.pagehelper.PageHelper">
<property name="dialect" value="mysql"/>
<property name="offsetAsPageNum" value="false"/>
<property name="rowBoundsWithCount" value="false"/>
<property name="pageSizeZero" value="true"/>
<property name="reasonable" value="false"/>
<property name="supportMethodsArguments" value="false"/>
<property name="returnPageInfo" value="none"/>
</plugin>
</plugins>
<!--<environments default="development">-->
<!--<environment id="development">-->
<!--<transactionManager type="JDBC"/>-->
<!--<dataSource type="POOLED">-->
<!--<property name="driver" value="com.mysql.jdbc.Driver"/>-->
<!--<property name="url" value="jdbc:mysql://localhost:3307/happy_home?serverTimezone=UTC"/>-->
<!--<property name="username" value="root"/>-->
<!--<property name="password" value="root"/>-->
<!--</dataSource>-->
<!--</environment>-->
<!--</environments>-->
<!--<mappers>-->
<!--<mapper resource="mapper/EmployeeMapper.xml" />-->
<!--</mappers>-->
</configuration>

154
strategydesign/woniu-web.iml

@ -0,0 +1,154 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="Spring" name="Spring">
<configuration />
</facet>
<facet type="web" name="Web">
<configuration>
<webroots />
<sourceRoots>
<root url="file://$MODULE_DIR$/src/main/java" />
<root url="file://$MODULE_DIR$/src/main/resources" />
</sourceRoots>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: com.github.rholder:guava-retrying:2.0.0" level="project" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:2.0.2" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:29.0-jre" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:failureaccess:1.0.1" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava" level="project" />
<orderEntry type="library" name="Maven: org.checkerframework:checker-qual:2.11.1" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.3.4" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.3" level="project" />
<orderEntry type="library" name="Maven: org.lionsoul:ip2region:2.7.0" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-aop:2.3.9.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.2.13.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.2.13.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.aspectj:aspectjweaver:1.9.6" level="project" />
<orderEntry type="library" name="Maven: cn.hutool:hutool-all:5.3.3" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:2.3.9.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:2.3.9.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.2.13.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.3.9.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-logging:2.3.9.RELEASE" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.2.3" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.2.3" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-to-slf4j:2.13.3" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.13.3" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.30" level="project" />
<orderEntry type="library" name="Maven: jakarta.annotation:jakarta.annotation-api:1.3.5" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.2.13.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.2.13.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.26" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-web:2.3.9.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-json:2.3.9.RELEASE" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.11.4" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.11.4" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.11.4" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.11.4" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.11.4" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-parameter-names:2.11.4" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-tomcat:2.3.9.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-core:9.0.43" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-websocket:9.0.43" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-web:5.2.13.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:5.2.13.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.2.13.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-test:2.3.9.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-test:2.3.9.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-test-autoconfigure:2.3.9.RELEASE" level="project" />
<orderEntry type="library" name="Maven: com.jayway.jsonpath:json-path:2.4.0" level="project" />
<orderEntry type="library" name="Maven: net.minidev:json-smart:2.3" level="project" />
<orderEntry type="library" name="Maven: net.minidev:accessors-smart:1.2" level="project" />
<orderEntry type="library" name="Maven: jakarta.xml.bind:jakarta.xml.bind-api:2.3.3" level="project" />
<orderEntry type="library" name="Maven: jakarta.activation:jakarta.activation-api:1.2.2" level="project" />
<orderEntry type="library" name="Maven: org.assertj:assertj-core:3.16.1" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest:2.2" level="project" />
<orderEntry type="library" name="Maven: org.junit.jupiter:junit-jupiter:5.6.3" level="project" />
<orderEntry type="library" name="Maven: org.junit.jupiter:junit-jupiter-api:5.6.3" level="project" />
<orderEntry type="library" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
<orderEntry type="library" name="Maven: org.junit.platform:junit-platform-commons:1.6.3" level="project" />
<orderEntry type="library" name="Maven: org.junit.jupiter:junit-jupiter-params:5.6.3" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.6.3" level="project" />
<orderEntry type="library" name="Maven: org.junit.vintage:junit-vintage-engine:5.6.3" level="project" />
<orderEntry type="library" name="Maven: org.apiguardian:apiguardian-api:1.1.0" level="project" />
<orderEntry type="library" name="Maven: org.junit.platform:junit-platform-engine:1.6.3" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.13.2" level="project" />
<orderEntry type="library" name="Maven: org.mockito:mockito-core:3.3.3" level="project" />
<orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy:1.10.20" level="project" />
<orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy-agent:1.10.20" level="project" />
<orderEntry type="library" name="Maven: org.objenesis:objenesis:2.6" level="project" />
<orderEntry type="library" name="Maven: org.mockito:mockito-junit-jupiter:3.3.3" level="project" />
<orderEntry type="library" name="Maven: org.skyscreamer:jsonassert:1.5.0" level="project" />
<orderEntry type="library" name="Maven: com.vaadin.external.google:android-json:0.0.20131108.vaadin1" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-test:5.2.13.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.xmlunit:xmlunit-core:2.7.0" level="project" />
<orderEntry type="library" name="Maven: org.projectlombok:lombok:1.18.18" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-cache:2.3.9.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-context-support:5.2.13.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.2" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-jdbc:2.3.9.RELEASE" level="project" />
<orderEntry type="library" name="Maven: com.zaxxer:HikariCP:3.4.5" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-jdbc:5.2.13.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-tx:5.2.13.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-autoconfigure:1.3.2" level="project" />
<orderEntry type="library" name="Maven: org.mybatis:mybatis:3.4.6" level="project" />
<orderEntry type="library" name="Maven: org.mybatis:mybatis-spring:1.3.2" level="project" />
<orderEntry type="library" name="Maven: com.alibaba:druid-spring-boot-starter:1.2.18" level="project" />
<orderEntry type="library" name="Maven: com.alibaba:druid:1.2.18" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.30" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jaxb:jaxb-runtime:2.3.3" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jaxb:txw2:2.3.3" level="project" />
<orderEntry type="library" name="Maven: com.sun.istack:istack-commons-runtime:3.0.11" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: com.sun.activation:jakarta.activation:1.2.2" level="project" />
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:8.0.29" level="project" />
<orderEntry type="library" name="Maven: com.alipay.sofa:runtime-sofa-boot-starter:3.18.0" level="project" />
<orderEntry type="library" name="Maven: com.alipay.sofa:runtime-sofa-boot:3.18.0" level="project" />
<orderEntry type="library" name="Maven: com.alipay.sofa:sofa-boot:3.18.0" level="project" />
<orderEntry type="library" name="Maven: com.alipay.sofa:log-sofa-boot-starter:3.18.0" level="project" />
<orderEntry type="library" name="Maven: com.alipay.sofa:log-sofa-boot:3.18.0" level="project" />
<orderEntry type="library" name="Maven: com.alipay.sofa.common:sofa-common-tools:1.3.6" level="project" />
<orderEntry type="library" name="Maven: com.alipay.sofa:sofa-ark-spi:1.1.5" level="project" />
<orderEntry type="library" name="Maven: com.alipay.sofa:sofa-ark-exception:1.1.5" level="project" />
<orderEntry type="library" name="Maven: com.alipay.sofa:sofa-boot-autoconfigure:3.18.0" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-validation:2.3.9.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.glassfish:jakarta.el:3.0.3" level="project" />
<orderEntry type="library" name="Maven: org.hibernate.validator:hibernate-validator:6.1.7.Final" level="project" />
<orderEntry type="library" name="Maven: jakarta.validation:jakarta.validation-api:2.0.2" level="project" />
<orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.4.1.Final" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml:classmate:1.5.1" level="project" />
<orderEntry type="library" name="Maven: com.github.ben-manes.caffeine:caffeine:2.9.3" level="project" />
<orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.76" level="project" />
<orderEntry type="library" name="Maven: com.alibaba:easyexcel:3.0.5" level="project" />
<orderEntry type="library" name="Maven: org.apache.poi:poi:4.1.2" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.14" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-collections4:4.4" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-math3:3.6.1" level="project" />
<orderEntry type="library" name="Maven: com.zaxxer:SparseBitSet:1.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.poi:poi-ooxml:4.1.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-compress:1.19" level="project" />
<orderEntry type="library" name="Maven: com.github.virtuald:curvesapi:1.06" level="project" />
<orderEntry type="library" name="Maven: org.apache.poi:poi-ooxml-schemas:4.1.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.xmlbeans:xmlbeans:3.1.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-csv:1.8" level="project" />
<orderEntry type="library" name="Maven: cglib:cglib:3.3.0" level="project" />
<orderEntry type="library" name="Maven: org.ow2.asm:asm:7.1" level="project" />
<orderEntry type="library" name="Maven: org.ehcache:ehcache:3.8.1" level="project" />
<orderEntry type="library" name="Maven: org.testng:testng:7.8.0" level="project" />
<orderEntry type="library" name="Maven: com.beust:jcommander:1.82" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.webjars:jquery:3.6.1" level="project" />
</component>
</module>
Loading…
Cancel
Save