🚀 feat(init): init

This commit is contained in:
Bunny 2024-07-28 18:29:50 +08:00
parent 6dd6dc98cd
commit 68c83f886f
19 changed files with 451 additions and 89 deletions

View File

@ -10,16 +10,16 @@ import java.util.Collections;
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 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 void main(String[] args) {
Generation("article");
Generation("t_userinfo");
}
/**
@ -41,7 +41,7 @@ public class NewCodeGet {
.packageConfig(builder -> {
builder.entity(entity)// 实体类包名
// TODO 父包名如果为空将下面子包名必须写全部 否则就只需写子包名
.parent("cn.bunny.service.web")
.parent("cn.bunny.service")
.controller("controller")// 控制层包名
.mapper("mapper")// mapper层包名
.service("service")// service层包名
@ -52,7 +52,7 @@ public class NewCodeGet {
.strategyConfig(builder -> {
// 设置要生成的表名
builder.addInclude(tableName)
//.addTablePrefix("sys_")// TODO 设置表前缀过滤
.addTablePrefix("t_")// TODO 设置表前缀过滤
.entityBuilder()
.enableLombok()
.enableChainModel()
@ -71,13 +71,6 @@ public class NewCodeGet {
.formatServiceImplFileName("%sServiceImpl")// 格式化 service 接口文件名称
.controllerBuilder()
.enableRestStyle();
})
// .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();
}).execute();
}
}

View File

@ -1,61 +1,36 @@
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.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* <p>
* 用户信息
*
* </p>
*
* @author Bunny
* @since 2024-05-17
* @since 2024-07-28
*/
@EqualsAndHashCode(callSuper = true)
@Data
@Getter
@Setter
@Accessors(chain = true)
@ApiModel(value = "User对象", description = "用户信息")
public class User extends BaseEntity implements Serializable {
@TableName("t_user")
@ApiModel(value = "User对象")
public class User implements Serializable {
@Serial
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("最后登录时间")
private LocalDateTime lastLoginTime;
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@ApiModelProperty("最后登录IP")
private String lastLoginIp;
@ApiModelProperty("最后登录ip地址")
private String lastLoginIpAddress;
@ApiModelProperty("积分")
private Integer totalIntegral;
@ApiModelProperty("当前积分")
private Integer currentIntegral;
@ApiModelProperty("0:禁用 1:正常")
private Byte status;
private String uname;
}

View File

@ -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;
}

View File

@ -40,7 +40,6 @@
<velocity.version>2.2</velocity.version>
<velocity-tools.version>3.1</velocity-tools.version>
<HikariCP.version>5.1.0</HikariCP.version>
<dynamic.datasource.version>4.3.1</dynamic.datasource.version>
</properties>
<dependencyManagement>
<dependencies>
@ -79,12 +78,6 @@
<artifactId>HikariCP</artifactId>
<version>${HikariCP.version}</version>
</dependency>
<!-- 多数据库源插件 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot3-starter</artifactId>
<version>${dynamic.datasource.version}</version>
</dependency>
<!-- knife4j -->
<dependency>
<groupId>com.github.xiaoymin</groupId>

View File

@ -55,16 +55,31 @@
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
<!-- 多数据库源插件 -->
<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 -->
<!-- shardingsphere -->
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<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>
</dependencies>

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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> {
}

View File

@ -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> {
}

View File

@ -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);
}

View File

@ -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> {
}

View File

@ -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);
}
}

View File

@ -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 {
}

View File

@ -1,8 +1,20 @@
bunny:
datasource:
master:
host: 192.168.3.98
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
password: "02120212"

View File

@ -1,8 +1,20 @@
bunny:
datasource:
master:
host: 192.168.3.98
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
password: "02120212"

View File

@ -6,22 +6,57 @@ spring:
active: @profiles.active@
application:
name: bunny-service
datasource:
dynamic:
primary: master #设置默认的数据源或者数据源组,默认值即为master
strict: false #严格匹配数据源,默认false. true未匹配到指定数据源时抛异常,false使用默认数据源
grace-destroy: false #是否优雅关闭数据源默认为false设置为true时关闭数据源时如果数据源中还存在活跃连接至多等待10s后强制关闭
datasource:
master:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://${bunny.datasource.host}:${bunny.datasource.port}/${bunny.datasource.sqlData}?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
username: ${bunny.datasource.username}
password: ${bunny.datasource.password}
aop:
enabled: true
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
data:
redis:
host: ${bunny.redis.host}
@ -34,7 +69,6 @@ spring:
max-wait: -1 #最大阻塞等待时间(负数表示没限制)
max-idle: 5 #最大空闲
min-idle: 0 #最小空闲
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
@ -49,9 +83,10 @@ mybatis-plus:
logging:
level:
cn.bunny.service.mapper: debug
cn.bunny.service.mapper: info
cn.bunny.service.controller: info
cn.bunny.service.service: info
root: info
pattern:
dateformat: HH:mm:ss:SSS
file:

View 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>

View File

@ -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>

View File

@ -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);
}
}