🤡 feat(非常激动): 成功了
This commit is contained in:
parent
f16550ddee
commit
1fce2ee8ec
|
@ -35,11 +35,5 @@
|
|||
<artifactId>ip2region</artifactId>
|
||||
<version>2.6.5</version>
|
||||
</dependency>
|
||||
<!-- ShardingSphere -->
|
||||
<dependency>
|
||||
<groupId>org.apache.shardingsphere</groupId>
|
||||
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
|
||||
<version>5.2.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -6,14 +6,8 @@ import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerIntercep
|
|||
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
|
||||
import org.mybatis.spring.SqlSessionFactoryBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
/**
|
||||
|
@ -23,8 +17,6 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|||
@Configuration
|
||||
@Slf4j
|
||||
public class MybatisPlusConfig {
|
||||
@Autowired
|
||||
private ShardingSphereDataSource dataSource;
|
||||
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
|
@ -42,17 +34,4 @@ public class MybatisPlusConfig {
|
|||
|
||||
return interceptor;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SqlSessionFactory sqlSessionFactory() throws Exception {
|
||||
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
|
||||
sqlSessionFactoryBean.setDataSource(dataSource);
|
||||
// 可以设置MyBatis-Plus的配置,比如mapper.xml的位置等
|
||||
return sqlSessionFactoryBean.getObject();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager transactionManager() {
|
||||
return new DataSourceTransactionManager(dataSource);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
package cn.bunny.entity.system.user;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-07-28
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
@TableName("t_userinfo")
|
||||
@ApiModel(value = "Userinfo对象", description = "")
|
||||
public class Userinfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
private String username;
|
||||
|
||||
private Integer age;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package cn.bunny.entity.system.user;
|
||||
package cn.bunny.entity.user;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
2
pom.xml
2
pom.xml
|
@ -27,7 +27,7 @@
|
|||
<java.version>21</java.version>
|
||||
<junit.version>3.8.1</junit.version>
|
||||
<mybatis-plus.version>3.5.6</mybatis-plus.version>
|
||||
<mysql.version>8.0.30</mysql.version>
|
||||
<mysql.version>8.0.29</mysql.version>
|
||||
<knife4j.version>4.5.0</knife4j.version>
|
||||
<fastjson2.version>2.0.47</fastjson2.version>
|
||||
<minio.version>8.5.9</minio.version>
|
||||
|
|
|
@ -55,6 +55,18 @@
|
|||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjweaver</artifactId>
|
||||
</dependency>
|
||||
<!-- ShardingSphere -->
|
||||
<dependency>
|
||||
<groupId>org.apache.shardingsphere</groupId>
|
||||
<artifactId>shardingsphere-jdbc</artifactId>
|
||||
<version>5.5.0</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.shardingsphere</groupId>
|
||||
<artifactId>shardingsphere-test-util</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package cn.bunny.service.controller;
|
||||
|
||||
import cn.bunny.entity.system.user.User;
|
||||
import cn.bunny.entity.user.User;
|
||||
import cn.bunny.pojo.result.Result;
|
||||
import cn.bunny.service.service.UserService;
|
||||
import cn.bunny.vo.page.PageResult;
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
package cn.bunny.service.controller;
|
||||
|
||||
import cn.bunny.entity.system.user.Userinfo;
|
||||
import cn.bunny.pojo.result.Result;
|
||||
import cn.bunny.service.service.UserinfoService;
|
||||
import cn.hutool.system.UserInfo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-07-28
|
||||
*/
|
||||
@Tag(name = "用户信息")
|
||||
@RestController
|
||||
@RequestMapping("/api/userinfo")
|
||||
public class UserinfoController {
|
||||
@Autowired
|
||||
private UserinfoService userinfoService;
|
||||
|
||||
@Operation(summary = "添加用户信息", description = "添加用户信息")
|
||||
@PostMapping("addUserinfo")
|
||||
public Result<UserInfo> addUserinfo(@RequestBody Userinfo userInfo) {
|
||||
userinfoService.save(userInfo);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package cn.bunny.service.mapper;
|
||||
|
||||
import cn.bunny.entity.system.user.User;
|
||||
import cn.bunny.entity.user.User;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
package cn.bunny.service.mapper;
|
||||
|
||||
import cn.bunny.entity.system.user.Userinfo;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-07-28
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserinfoMapper extends BaseMapper<Userinfo> {
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package cn.bunny.service.service;
|
||||
|
||||
import cn.bunny.entity.system.user.User;
|
||||
import cn.bunny.entity.user.User;
|
||||
import cn.bunny.vo.page.PageResult;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
package cn.bunny.service.service;
|
||||
|
||||
import cn.bunny.entity.system.user.Userinfo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-07-28
|
||||
*/
|
||||
public interface UserinfoService extends IService<Userinfo> {
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package cn.bunny.service.service.impl;
|
||||
|
||||
import cn.bunny.entity.system.user.User;
|
||||
import cn.bunny.entity.user.User;
|
||||
import cn.bunny.service.mapper.UserMapper;
|
||||
import cn.bunny.service.service.UserService;
|
||||
import cn.bunny.vo.page.PageResult;
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
package cn.bunny.service.service.impl;
|
||||
|
||||
import cn.bunny.entity.system.user.Userinfo;
|
||||
import cn.bunny.service.mapper.UserinfoMapper;
|
||||
import cn.bunny.service.service.UserinfoService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-07-28
|
||||
*/
|
||||
@Service
|
||||
public class UserinfoServiceImpl extends ServiceImpl<UserinfoMapper, Userinfo> implements UserinfoService {
|
||||
|
||||
}
|
|
@ -1,18 +1,18 @@
|
|||
bunny:
|
||||
master:
|
||||
host: 192.168.3.98
|
||||
host: 192.168.3.21
|
||||
port: 3306
|
||||
sqlData: db_user
|
||||
username: root
|
||||
password: "02120212"
|
||||
slave1:
|
||||
host: 192.168.3.98
|
||||
host: 192.168.3.21
|
||||
port: 3307
|
||||
sqlData: db_user
|
||||
username: root
|
||||
password: "02120212"
|
||||
slave2:
|
||||
host: 192.168.3.98
|
||||
host: 192.168.3.21
|
||||
port: 3308
|
||||
sqlData: db_user
|
||||
username: root
|
||||
|
|
|
@ -7,57 +7,14 @@ spring:
|
|||
active: @profiles.active@
|
||||
application:
|
||||
name: bunny-service
|
||||
# datasource:
|
||||
# # 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}
|
||||
datasource:
|
||||
driver-class-name: org.apache.shardingsphere.driver.ShardingSphereDriver
|
||||
url: jdbc:shardingsphere:classpath:sharding.yaml
|
||||
|
||||
shardingsphere:
|
||||
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:
|
||||
readwrite_ds:
|
||||
static-strategy:
|
||||
write-data-source-name: master
|
||||
read-data-source-names: slave1, slave2
|
||||
load-balancer-name: round_robin
|
||||
load-balancers:
|
||||
round_robin:
|
||||
type: ROUND_ROBIN
|
||||
sharding:
|
||||
default-database-strategy:
|
||||
hint:
|
||||
sharding-algorithm-name: master
|
||||
|
||||
jackson:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
time-zone: GMT+8
|
||||
|
||||
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath:mapper/*.xml
|
||||
configuration:
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<mapper namespace="cn.bunny.service.mapper.UserMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="cn.bunny.entity.system.user.User">
|
||||
<resultMap id="BaseResultMap" type="cn.bunny.entity.user.User">
|
||||
<id column="id" property="id"/>
|
||||
<result column="uname" property="uname"/>
|
||||
</resultMap>
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
<?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="cn.bunny.service.mapper.UserinfoMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="cn.bunny.entity.system.user.Userinfo">
|
||||
<id column="id" property="id"/>
|
||||
<result column="username" property="username"/>
|
||||
<result column="age" property="age"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, username, age
|
||||
</sql>
|
||||
|
||||
</mapper>
|
|
@ -3,27 +3,31 @@ mode:
|
|||
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
|
||||
driverClassName: com.mysql.cj.jdbc.Driver
|
||||
jdbcUrl: jdbc:mysql://192.168.3.21:3306/db_user?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
|
||||
username: root
|
||||
password: 02120212
|
||||
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
|
||||
driverClassName: com.mysql.cj.jdbc.Driver
|
||||
jdbcUrl: jdbc:mysql://192.168.3.21:3307/db_user?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
|
||||
username: root
|
||||
password: 02120212
|
||||
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
|
||||
driverClassName: com.mysql.cj.jdbc.Driver
|
||||
jdbcUrl: jdbc:mysql://192.168.3.21:3308/db_user?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
|
||||
username: root
|
||||
password: 02120212
|
||||
password: "02120212"
|
||||
rules:
|
||||
dataSourceGroups:
|
||||
- !SINGLE
|
||||
tables:
|
||||
- "*.*"
|
||||
defaultDataSource: master
|
||||
- !READWRITE_SPLITTING
|
||||
dataSources:
|
||||
readwrite_ds:
|
||||
writeDataSourceName: master
|
||||
readDataSourceNames:
|
||||
|
@ -34,3 +38,17 @@ rules:
|
|||
loadBalancers:
|
||||
random:
|
||||
type: RANDOM
|
||||
props:
|
||||
sql-show: true
|
||||
|
||||
sqlParser:
|
||||
sqlStatementCache:
|
||||
initialCapacity: 2000
|
||||
maximumSize: 65535
|
||||
parseTreeCache:
|
||||
initialCapacity: 128
|
||||
maximumSize: 1024
|
||||
|
||||
sqlTranslator:
|
||||
type: Native
|
||||
useOriginalSQLWhenTranslatingFailed: true
|
|
@ -1,6 +1,6 @@
|
|||
package cn.bunny.service.service.impl;
|
||||
|
||||
import cn.bunny.entity.system.user.User;
|
||||
import cn.bunny.entity.user.User;
|
||||
import cn.bunny.service.mapper.UserMapper;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
Loading…
Reference in New Issue