🚀 feat(新增): 配置相关
This commit is contained in:
parent
68c83f886f
commit
ce302fd8f5
|
@ -30,10 +30,4 @@ public class Knife4jConfig {
|
||||||
public GroupedOpenApi groupedOpenApi() {
|
public GroupedOpenApi groupedOpenApi() {
|
||||||
return GroupedOpenApi.builder().group("web前台接口管理").pathsToMatch("/api/**").build();
|
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 -->
|
<!-- shardingsphere -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.shardingsphere</groupId>
|
<groupId>org.apache.shardingsphere</groupId>
|
||||||
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
|
<artifactId>shardingsphere-jdbc-core</artifactId>
|
||||||
<version>5.1.1</version>
|
<version>5.4.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-io</groupId>
|
<groupId>org.apache.shardingsphere</groupId>
|
||||||
<artifactId>commons-io</artifactId>
|
<artifactId>shardingsphere-jdbc</artifactId>
|
||||||
<version>2.15.1</version>
|
<version>5.4.1</version>
|
||||||
</dependency>
|
<type>pom</type>
|
||||||
<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>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -1,21 +1,13 @@
|
||||||
package cn.bunny.service;
|
package cn.bunny.service;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
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;
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
@ComponentScan(basePackages = {"cn.bunny"})
|
|
||||||
@MapperScan("cn.bunny.service.mapper")
|
@MapperScan("cn.bunny.service.mapper")
|
||||||
@EnableScheduling// 定时任务
|
|
||||||
@EnableCaching// 开启缓存注解
|
|
||||||
@EnableTransactionManagement// 开启事务注解
|
@EnableTransactionManagement// 开启事务注解
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@Slf4j
|
|
||||||
public class ServiceApplication {
|
public class ServiceApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(ServiceApplication.class, args);
|
SpringApplication.run(ServiceApplication.class, args);
|
||||||
|
|
|
@ -7,56 +7,15 @@ spring:
|
||||||
application:
|
application:
|
||||||
name: bunny-service
|
name: bunny-service
|
||||||
datasource:
|
datasource:
|
||||||
type: com.zaxxer.hikari.HikariDataSource
|
driver-class-name: org.apache.shardingsphere.driver.ShardingSphereDriver
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
url: jdbc:shardingsphere:classpath:static/shardingsphere.yaml
|
||||||
url: jdbc:mysql://${bunny.master.host}:${bunny.master.port}/${bunny.master.sqlData}?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
|
# type: com.zaxxer.hikari.HikariDataSource
|
||||||
username: ${bunny.master.username}
|
# driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
password: ${bunny.master.password}
|
# url: jdbc:mysql://${bunny.master.host}:${bunny.master.port}/${bunny.master.sqlData}?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
|
||||||
shardingsphere:
|
# username: ${bunny.master.username}
|
||||||
mode:
|
# password: ${bunny.master.password}
|
||||||
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
|
|
||||||
data:
|
data:
|
||||||
redis:
|
redis:
|
||||||
host: ${bunny.redis.host}
|
host: ${bunny.redis.host}
|
||||||
|
@ -75,18 +34,10 @@ spring:
|
||||||
|
|
||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
mapper-locations: classpath:mapper/*.xml
|
mapper-locations: classpath:mapper/*.xml
|
||||||
global-config:
|
|
||||||
db-config:
|
|
||||||
logic-delete-field: isDelete
|
|
||||||
configuration:
|
configuration:
|
||||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 查看日志
|
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 查看日志
|
||||||
|
|
||||||
logging:
|
logging:
|
||||||
level:
|
|
||||||
cn.bunny.service.mapper: info
|
|
||||||
cn.bunny.service.controller: info
|
|
||||||
cn.bunny.service.service: info
|
|
||||||
root: info
|
|
||||||
pattern:
|
pattern:
|
||||||
dateformat: HH:mm:ss:SSS
|
dateformat: HH:mm:ss:SSS
|
||||||
file:
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
class UserServiceImplTest {
|
class UserServiceImplTest {
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserMapper userMapper;
|
private UserMapper userMapper;
|
||||||
|
|
||||||
|
// 添加用户
|
||||||
@Test
|
@Test
|
||||||
void addUser() {
|
void addUser() {
|
||||||
User user = new User();
|
User user = new User();
|
||||||
|
@ -19,11 +22,18 @@ class UserServiceImplTest {
|
||||||
userMapper.insert(user);
|
userMapper.insert(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 事务使用
|
||||||
@Test
|
@Test
|
||||||
@Transactional
|
@Transactional
|
||||||
void addTransactional() {
|
void addTransactional() {
|
||||||
User user = new User();
|
User user = new User();
|
||||||
user.setUname("喜欢凌艳");
|
user.setUname("哈哈哈");
|
||||||
userMapper.insert(user);
|
userMapper.insert(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void selectUseList() {
|
||||||
|
List<User> users = userMapper.selectList(null);
|
||||||
|
users.forEach(System.out::println);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue