🚀 feat(新增): 配置相关
This commit is contained in:
parent
68c83f886f
commit
ce302fd8f5
|
@ -30,10 +30,4 @@ public class Knife4jConfig {
|
|||
public GroupedOpenApi groupedOpenApi() {
|
||||
return GroupedOpenApi.builder().group("web前台接口管理").pathsToMatch("/api/**").build();
|
||||
}
|
||||
|
||||
// 管理员相关分类接口
|
||||
@Bean
|
||||
public GroupedOpenApi groupedOpenAdminApi() {
|
||||
return GroupedOpenApi.builder().group("admin管理员接口请求").pathsToMatch("/admin/**").build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
package cn.bunny.common.service.config;
|
||||
|
||||
import cn.bunny.common.service.context.BaseContext;
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 配置MP在修改和新增时的操作
|
||||
*/
|
||||
@Component
|
||||
public class MyBatisPlusFieldConfig implements MetaObjectHandler {
|
||||
|
||||
/**
|
||||
* 使用mp做添加操作时候,这个方法执行
|
||||
*/
|
||||
@Override
|
||||
public void insertFill(MetaObject metaObject) {
|
||||
// 设置属性值
|
||||
this.setFieldValByName("createTime", new Date(), metaObject);
|
||||
this.setFieldValByName("updateTime", new Date(), metaObject);
|
||||
this.setFieldValByName("deleteStatus", 1, metaObject);
|
||||
if (BaseContext.getUsername() != null) {
|
||||
this.setFieldValByName("createBy", BaseContext.getUsername(), metaObject);
|
||||
this.setFieldValByName("updateBy", BaseContext.getUsername(), metaObject);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用mp做修改操作时候,这个方法执行
|
||||
*/
|
||||
@Override
|
||||
public void updateFill(MetaObject metaObject) {
|
||||
this.setFieldValByName("updateTime", new Date(), metaObject);
|
||||
this.setFieldValByName("updateBy", BaseContext.getUsername(), metaObject);
|
||||
}
|
||||
}
|
|
@ -58,29 +58,16 @@
|
|||
<!-- shardingsphere -->
|
||||
<dependency>
|
||||
<groupId>org.apache.shardingsphere</groupId>
|
||||
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
|
||||
<version>5.1.1</version>
|
||||
<artifactId>shardingsphere-jdbc-core</artifactId>
|
||||
<version>5.4.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.15.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.calcite.avatica</groupId>
|
||||
<artifactId>avatica-core</artifactId>
|
||||
<version>1.22.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.calcite</groupId>
|
||||
<artifactId>calcite-core</artifactId>
|
||||
<version>1.32.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
<version>4.5.0-M2</version>
|
||||
<groupId>org.apache.shardingsphere</groupId>
|
||||
<artifactId>shardingsphere-jdbc</artifactId>
|
||||
<version>5.4.1</version>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -1,21 +1,13 @@
|
|||
package cn.bunny.service;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@ComponentScan(basePackages = {"cn.bunny"})
|
||||
@MapperScan("cn.bunny.service.mapper")
|
||||
@EnableScheduling// 定时任务
|
||||
@EnableCaching// 开启缓存注解
|
||||
@EnableTransactionManagement// 开启事务注解
|
||||
@SpringBootApplication
|
||||
@Slf4j
|
||||
public class ServiceApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ServiceApplication.class, args);
|
||||
|
|
|
@ -7,56 +7,15 @@ spring:
|
|||
application:
|
||||
name: bunny-service
|
||||
datasource:
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://${bunny.master.host}:${bunny.master.port}/${bunny.master.sqlData}?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
|
||||
username: ${bunny.master.username}
|
||||
password: ${bunny.master.password}
|
||||
shardingsphere:
|
||||
mode:
|
||||
type: Memory
|
||||
datasource:
|
||||
names: master,slave1,slave2
|
||||
master:
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
jdbc-url: jdbc:mysql://${bunny.master.host}:${bunny.master.port}/${bunny.master.sqlData}?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
|
||||
username: ${bunny.master.username}
|
||||
password: ${bunny.master.password}
|
||||
slave1:
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
jdbc-url: jdbc:mysql://${bunny.slave1.host}:${bunny.slave1.port}/${bunny.slave1.sqlData}?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
|
||||
username: ${bunny.slave1.username}
|
||||
password: ${bunny.slave1.password}
|
||||
slave2:
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
jdbc-url: jdbc:mysql://${bunny.slave2.host}:${bunny.slave2.port}/${bunny.slave2.sqlData}?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
|
||||
username: ${bunny.slave2.username}
|
||||
password: ${bunny.slave2.password}
|
||||
rules:
|
||||
readwrite-splitting:
|
||||
data-sources:
|
||||
myDS:
|
||||
type: Static
|
||||
props:
|
||||
write-data-source-name: master
|
||||
read-data-source-names: slave1,slave2
|
||||
load-balancers:
|
||||
load-balancer-name: alg_round
|
||||
load-balancers:
|
||||
alg_round:
|
||||
type: ROUND_ROBIN
|
||||
alg_random:
|
||||
type: RANDOM
|
||||
alg_weight:
|
||||
type: WEIGHT
|
||||
props:
|
||||
- slave1: 1
|
||||
- slave2: 2
|
||||
props:
|
||||
sql-show: true
|
||||
driver-class-name: org.apache.shardingsphere.driver.ShardingSphereDriver
|
||||
url: jdbc:shardingsphere:classpath:static/shardingsphere.yaml
|
||||
# type: com.zaxxer.hikari.HikariDataSource
|
||||
# driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
# url: jdbc:mysql://${bunny.master.host}:${bunny.master.port}/${bunny.master.sqlData}?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
|
||||
# username: ${bunny.master.username}
|
||||
# password: ${bunny.master.password}
|
||||
|
||||
|
||||
data:
|
||||
redis:
|
||||
host: ${bunny.redis.host}
|
||||
|
@ -75,18 +34,10 @@ spring:
|
|||
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath:mapper/*.xml
|
||||
global-config:
|
||||
db-config:
|
||||
logic-delete-field: isDelete
|
||||
configuration:
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 查看日志
|
||||
|
||||
logging:
|
||||
level:
|
||||
cn.bunny.service.mapper: info
|
||||
cn.bunny.service.controller: info
|
||||
cn.bunny.service.service: info
|
||||
root: info
|
||||
pattern:
|
||||
dateformat: HH:mm:ss:SSS
|
||||
file:
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
mode:
|
||||
type: Standalone
|
||||
repository:
|
||||
type: JDBC
|
||||
dataSources:
|
||||
|
||||
master:
|
||||
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
|
||||
driverClassName: com.mysql.jdbc.Driver
|
||||
jdbcUrl: jdbc:mysql://192.168.3.98:3306/db_user?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
|
||||
username: root
|
||||
password: 02120212
|
||||
slave1:
|
||||
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
|
||||
driverClassName: com.mysql.jdbc.Driver
|
||||
jdbcUrl: jdbc:mysql://192.168.3.98:3307/db_user?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
|
||||
username: root
|
||||
password: 02120212
|
||||
slave2:
|
||||
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
|
||||
driverClassName: com.mysql.jdbc.Driver
|
||||
jdbcUrl: jdbc:mysql://192.168.3.98:3308/db_user?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
|
||||
username: root
|
||||
password: 02120212
|
||||
rules:
|
||||
dataSourceGroups:
|
||||
readwrite_ds:
|
||||
writeDataSourceName: master
|
||||
readDataSourceNames:
|
||||
- slave1
|
||||
- slave2
|
||||
transactionalReadQueryStrategy: PRIMARY
|
||||
loadBalancerName: random
|
||||
loadBalancers:
|
||||
random:
|
||||
type: RANDOM
|
|
@ -7,11 +7,14 @@ import org.junit.jupiter.api.Test;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
class UserServiceImplTest {
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
// 添加用户
|
||||
@Test
|
||||
void addUser() {
|
||||
User user = new User();
|
||||
|
@ -19,11 +22,18 @@ class UserServiceImplTest {
|
|||
userMapper.insert(user);
|
||||
}
|
||||
|
||||
// 事务使用
|
||||
@Test
|
||||
@Transactional
|
||||
void addTransactional() {
|
||||
User user = new User();
|
||||
user.setUname("喜欢凌艳");
|
||||
user.setUname("哈哈哈");
|
||||
userMapper.insert(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
void selectUseList() {
|
||||
List<User> users = userMapper.selectList(null);
|
||||
users.forEach(System.out::println);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue