🚀 feat(init): init
This commit is contained in:
parent
6dd6dc98cd
commit
68c83f886f
|
@ -10,16 +10,16 @@ import java.util.Collections;
|
||||||
|
|
||||||
public class NewCodeGet {
|
public class NewCodeGet {
|
||||||
// 数据连接
|
// 数据连接
|
||||||
public static final String sqlHost = "jdbc:mysql://106.15.251.123:3305/bunny_docs?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true";
|
public static final String sqlHost = "jdbc:mysql://192.168.3.98:3306/db_user?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true";
|
||||||
// 作者名称
|
// 作者名称
|
||||||
public static final String author = "Bunny";
|
public static final String author = "Bunny";
|
||||||
// 公共路径
|
// 公共路径
|
||||||
public static final String outputDir = "F:\\web项目\\PC\\BunnyNote\\BunnyBBS-server\\service\\service-web";
|
public static final String outputDir = "D:\\Project\\demo\\sharding-sphere5\\service";
|
||||||
// 实体类名称
|
// 实体类名称
|
||||||
public static final String entity = "Bunny";
|
public static final String entity = "Bunny";
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Generation("article");
|
Generation("t_userinfo");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,7 +41,7 @@ public class NewCodeGet {
|
||||||
.packageConfig(builder -> {
|
.packageConfig(builder -> {
|
||||||
builder.entity(entity)// 实体类包名
|
builder.entity(entity)// 实体类包名
|
||||||
// TODO 父包名。如果为空,将下面子包名必须写全部, 否则就只需写子包名
|
// TODO 父包名。如果为空,将下面子包名必须写全部, 否则就只需写子包名
|
||||||
.parent("cn.bunny.service.web")
|
.parent("cn.bunny.service")
|
||||||
.controller("controller")// 控制层包名
|
.controller("controller")// 控制层包名
|
||||||
.mapper("mapper")// mapper层包名
|
.mapper("mapper")// mapper层包名
|
||||||
.service("service")// service层包名
|
.service("service")// service层包名
|
||||||
|
@ -52,7 +52,7 @@ public class NewCodeGet {
|
||||||
.strategyConfig(builder -> {
|
.strategyConfig(builder -> {
|
||||||
// 设置要生成的表名
|
// 设置要生成的表名
|
||||||
builder.addInclude(tableName)
|
builder.addInclude(tableName)
|
||||||
//.addTablePrefix("sys_")// TODO 设置表前缀过滤
|
.addTablePrefix("t_")// TODO 设置表前缀过滤
|
||||||
.entityBuilder()
|
.entityBuilder()
|
||||||
.enableLombok()
|
.enableLombok()
|
||||||
.enableChainModel()
|
.enableChainModel()
|
||||||
|
@ -71,13 +71,6 @@ public class NewCodeGet {
|
||||||
.formatServiceImplFileName("%sServiceImpl")// 格式化 service 接口文件名称
|
.formatServiceImplFileName("%sServiceImpl")// 格式化 service 接口文件名称
|
||||||
.controllerBuilder()
|
.controllerBuilder()
|
||||||
.enableRestStyle();
|
.enableRestStyle();
|
||||||
})
|
}).execute();
|
||||||
// .injectionConfig(consumer -> {
|
|
||||||
// Map<String, String> customFile = new HashMap<>();
|
|
||||||
// // 配置DTO(需要的话)但是需要有能配置Dto的模板引擎,比如freemarker,但是这里我们用的VelocityEngine,因此不多作介绍
|
|
||||||
// customFile.put(outputDir, "/src/main/resources/templates/entityDTO.java.ftl");
|
|
||||||
// consumer.customFile(customFile);
|
|
||||||
// })
|
|
||||||
.execute();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,61 +1,36 @@
|
||||||
package cn.bunny.entity.system.user;
|
package cn.bunny.entity.system.user;
|
||||||
|
|
||||||
import cn.bunny.entity.base.BaseEntity;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import lombok.Getter;
|
||||||
import lombok.Data;
|
import lombok.Setter;
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 用户信息
|
*
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Bunny
|
* @author Bunny
|
||||||
* @since 2024-05-17
|
* @since 2024-07-28
|
||||||
*/
|
*/
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@Getter
|
||||||
@Data
|
@Setter
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
@ApiModel(value = "User对象", description = "用户信息")
|
@TableName("t_user")
|
||||||
public class User extends BaseEntity implements Serializable {
|
@ApiModel(value = "User对象")
|
||||||
|
public class User implements Serializable {
|
||||||
|
|
||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
@ApiModelProperty("昵称")
|
|
||||||
private String nickName;
|
|
||||||
@ApiModelProperty("邮箱")
|
|
||||||
private String email;
|
|
||||||
@ApiModelProperty("密码")
|
|
||||||
private String password;
|
|
||||||
@ApiModelProperty("头像")
|
|
||||||
private String avatar;
|
|
||||||
@ApiModelProperty("0:女 1:男")
|
|
||||||
private Byte sex;
|
|
||||||
@ApiModelProperty("个人描述")
|
|
||||||
private String personDescription;
|
|
||||||
@ApiModelProperty("加入时间")
|
|
||||||
private LocalDateTime joinTime;
|
|
||||||
|
|
||||||
@ApiModelProperty("最后登录时间")
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
private LocalDateTime lastLoginTime;
|
private Long id;
|
||||||
|
|
||||||
@ApiModelProperty("最后登录IP")
|
private String uname;
|
||||||
private String lastLoginIp;
|
|
||||||
|
|
||||||
@ApiModelProperty("最后登录ip地址")
|
|
||||||
private String lastLoginIpAddress;
|
|
||||||
|
|
||||||
@ApiModelProperty("积分")
|
|
||||||
private Integer totalIntegral;
|
|
||||||
|
|
||||||
@ApiModelProperty("当前积分")
|
|
||||||
private Integer currentIntegral;
|
|
||||||
|
|
||||||
@ApiModelProperty("0:禁用 1:正常")
|
|
||||||
private Byte status;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
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;
|
||||||
|
}
|
7
pom.xml
7
pom.xml
|
@ -40,7 +40,6 @@
|
||||||
<velocity.version>2.2</velocity.version>
|
<velocity.version>2.2</velocity.version>
|
||||||
<velocity-tools.version>3.1</velocity-tools.version>
|
<velocity-tools.version>3.1</velocity-tools.version>
|
||||||
<HikariCP.version>5.1.0</HikariCP.version>
|
<HikariCP.version>5.1.0</HikariCP.version>
|
||||||
<dynamic.datasource.version>4.3.1</dynamic.datasource.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -79,12 +78,6 @@
|
||||||
<artifactId>HikariCP</artifactId>
|
<artifactId>HikariCP</artifactId>
|
||||||
<version>${HikariCP.version}</version>
|
<version>${HikariCP.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- 多数据库源插件 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.baomidou</groupId>
|
|
||||||
<artifactId>dynamic-datasource-spring-boot3-starter</artifactId>
|
|
||||||
<version>${dynamic.datasource.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<!-- knife4j -->
|
<!-- knife4j -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.xiaoymin</groupId>
|
<groupId>com.github.xiaoymin</groupId>
|
||||||
|
|
|
@ -55,16 +55,31 @@
|
||||||
<groupId>org.aspectj</groupId>
|
<groupId>org.aspectj</groupId>
|
||||||
<artifactId>aspectjweaver</artifactId>
|
<artifactId>aspectjweaver</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- 多数据库源插件 -->
|
<!-- shardingsphere -->
|
||||||
<dependency>
|
|
||||||
<groupId>com.baomidou</groupId>
|
|
||||||
<artifactId>dynamic-datasource-spring-boot3-starter</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<!-- https://mvnrepository.com/artifact/org.apache.shardingsphere/shardingsphere-jdbc-core-spring-boot-starter -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.shardingsphere</groupId>
|
<groupId>org.apache.shardingsphere</groupId>
|
||||||
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
|
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
|
||||||
<version>5.2.1</version>
|
<version>5.1.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>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
package cn.bunny.service.controller;
|
||||||
|
|
||||||
|
import cn.bunny.entity.system.user.User;
|
||||||
|
import cn.bunny.pojo.result.Result;
|
||||||
|
import cn.bunny.service.service.UserService;
|
||||||
|
import cn.bunny.vo.page.PageResult;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
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.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 前端控制器
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Bunny
|
||||||
|
* @since 2024-07-28
|
||||||
|
*/
|
||||||
|
@Tag(name = "用户表")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/user")
|
||||||
|
public class UserController {
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
@Operation(summary = "查询所有用户", description = "查询所有用户")
|
||||||
|
@GetMapping("/{page}/{limit}")
|
||||||
|
public Result<PageResult<User>> queryPage(@PathVariable Integer page, @PathVariable Integer limit) {
|
||||||
|
Page<User> parParams = new Page<>(page, limit);
|
||||||
|
PageResult<User> vo = userService.queryPage(parParams);
|
||||||
|
return Result.success(vo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "添加用户", description = "添加用户")
|
||||||
|
@PostMapping("addUser")
|
||||||
|
public Result<User> addUser(@RequestBody User user) {
|
||||||
|
userService.addUser(user);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package cn.bunny.service.mapper;
|
||||||
|
|
||||||
|
import cn.bunny.entity.system.user.User;
|
||||||
|
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 UserMapper extends BaseMapper<User> {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
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> {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package cn.bunny.service.service;
|
||||||
|
|
||||||
|
import cn.bunny.entity.system.user.User;
|
||||||
|
import cn.bunny.vo.page.PageResult;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 服务类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Bunny
|
||||||
|
* @since 2024-07-28
|
||||||
|
*/
|
||||||
|
public interface UserService extends IService<User> {
|
||||||
|
/**
|
||||||
|
* * 查询所有用户
|
||||||
|
*
|
||||||
|
* @param parParams 分页参数
|
||||||
|
* @return 分页结果
|
||||||
|
*/
|
||||||
|
PageResult<User> queryPage(Page<User> parParams);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 添加用户
|
||||||
|
*
|
||||||
|
* @param user 添加用户
|
||||||
|
*/
|
||||||
|
void addUser(User user);
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
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> {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
package cn.bunny.service.service.impl;
|
||||||
|
|
||||||
|
import cn.bunny.entity.system.user.User;
|
||||||
|
import cn.bunny.service.mapper.UserMapper;
|
||||||
|
import cn.bunny.service.service.UserService;
|
||||||
|
import cn.bunny.vo.page.PageResult;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 服务实现类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Bunny
|
||||||
|
* @since 2024-07-28
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 查询所有用户
|
||||||
|
*
|
||||||
|
* @param parParams 分页参数
|
||||||
|
* @return 分页结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PageResult<User> queryPage(Page<User> parParams) {
|
||||||
|
Page<User> page = page(parParams);
|
||||||
|
return PageResult.<User>builder()
|
||||||
|
.pageNo((int) page.getCurrent())
|
||||||
|
.pageSize((int) page.getSize())
|
||||||
|
.total(page.getTotal())
|
||||||
|
.list(page.getRecords())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 添加用户
|
||||||
|
*
|
||||||
|
* @param user 添加用户
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void addUser(User user) {
|
||||||
|
save(user);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
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,8 +1,20 @@
|
||||||
bunny:
|
bunny:
|
||||||
datasource:
|
master:
|
||||||
host: 192.168.3.98
|
host: 192.168.3.98
|
||||||
port: 3306
|
port: 3306
|
||||||
sqlData: bunny_docs
|
sqlData: db_user
|
||||||
|
username: root
|
||||||
|
password: "02120212"
|
||||||
|
slave1:
|
||||||
|
host: 192.168.3.98
|
||||||
|
port: 3307
|
||||||
|
sqlData: db_user
|
||||||
|
username: root
|
||||||
|
password: "02120212"
|
||||||
|
slave2:
|
||||||
|
host: 192.168.3.98
|
||||||
|
port: 3308
|
||||||
|
sqlData: db_user
|
||||||
username: root
|
username: root
|
||||||
password: "02120212"
|
password: "02120212"
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,20 @@
|
||||||
bunny:
|
bunny:
|
||||||
datasource:
|
master:
|
||||||
host: 192.168.3.98
|
host: 192.168.3.98
|
||||||
port: 3306
|
port: 3306
|
||||||
sqlData: bunny_docs
|
sqlData: db_user
|
||||||
|
username: root
|
||||||
|
password: "02120212"
|
||||||
|
slave1:
|
||||||
|
host: 192.168.3.98
|
||||||
|
port: 3307
|
||||||
|
sqlData: db_user
|
||||||
|
username: root
|
||||||
|
password: "02120212"
|
||||||
|
slave2:
|
||||||
|
host: 192.168.3.98
|
||||||
|
port: 3308
|
||||||
|
sqlData: db_user
|
||||||
username: root
|
username: root
|
||||||
password: "02120212"
|
password: "02120212"
|
||||||
|
|
||||||
|
|
|
@ -6,22 +6,57 @@ spring:
|
||||||
active: @profiles.active@
|
active: @profiles.active@
|
||||||
application:
|
application:
|
||||||
name: bunny-service
|
name: bunny-service
|
||||||
|
|
||||||
datasource:
|
datasource:
|
||||||
dynamic:
|
type: com.zaxxer.hikari.HikariDataSource
|
||||||
primary: master #设置默认的数据源或者数据源组,默认值即为master
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
strict: false #严格匹配数据源,默认false. true未匹配到指定数据源时抛异常,false使用默认数据源
|
url: jdbc:mysql://${bunny.master.host}:${bunny.master.port}/${bunny.master.sqlData}?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
|
||||||
grace-destroy: false #是否优雅关闭数据源,默认为false,设置为true时,关闭数据源时如果数据源中还存在活跃连接,至多等待10s后强制关闭
|
username: ${bunny.master.username}
|
||||||
datasource:
|
password: ${bunny.master.password}
|
||||||
master:
|
shardingsphere:
|
||||||
type: com.zaxxer.hikari.HikariDataSource
|
mode:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
type: Memory
|
||||||
url: jdbc:mysql://${bunny.datasource.host}:${bunny.datasource.port}/${bunny.datasource.sqlData}?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
|
datasource:
|
||||||
username: ${bunny.datasource.username}
|
names: master,slave1,slave2
|
||||||
password: ${bunny.datasource.password}
|
master:
|
||||||
aop:
|
type: com.zaxxer.hikari.HikariDataSource
|
||||||
enabled: true
|
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}
|
||||||
|
@ -34,7 +69,6 @@ spring:
|
||||||
max-wait: -1 #最大阻塞等待时间(负数表示没限制)
|
max-wait: -1 #最大阻塞等待时间(负数表示没限制)
|
||||||
max-idle: 5 #最大空闲
|
max-idle: 5 #最大空闲
|
||||||
min-idle: 0 #最小空闲
|
min-idle: 0 #最小空闲
|
||||||
|
|
||||||
jackson:
|
jackson:
|
||||||
date-format: yyyy-MM-dd HH:mm:ss
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
time-zone: GMT+8
|
time-zone: GMT+8
|
||||||
|
@ -49,9 +83,10 @@ mybatis-plus:
|
||||||
|
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
cn.bunny.service.mapper: debug
|
cn.bunny.service.mapper: info
|
||||||
cn.bunny.service.controller: info
|
cn.bunny.service.controller: info
|
||||||
cn.bunny.service.service: 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,16 @@
|
||||||
|
<?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.UserMapper">
|
||||||
|
|
||||||
|
<!-- 通用查询映射结果 -->
|
||||||
|
<resultMap id="BaseResultMap" type="cn.bunny.entity.system.user.User">
|
||||||
|
<id column="id" property="id"/>
|
||||||
|
<result column="uname" property="uname"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<!-- 通用查询结果列 -->
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
id, uname
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
</mapper>
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?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>
|
|
@ -0,0 +1,29 @@
|
||||||
|
package cn.bunny.service.service.impl;
|
||||||
|
|
||||||
|
import cn.bunny.entity.system.user.User;
|
||||||
|
import cn.bunny.service.mapper.UserMapper;
|
||||||
|
import jakarta.transaction.Transactional;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
class UserServiceImplTest {
|
||||||
|
@Autowired
|
||||||
|
private UserMapper userMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void addUser() {
|
||||||
|
User user = new User();
|
||||||
|
user.setUname("啊啊啊");
|
||||||
|
userMapper.insert(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Transactional
|
||||||
|
void addTransactional() {
|
||||||
|
User user = new User();
|
||||||
|
user.setUname("喜欢凌艳");
|
||||||
|
userMapper.insert(user);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue