From 68c83f886ff87239f286aa1d2af698bf406ef032 Mon Sep 17 00:00:00 2001 From: Bunny <1319900154@qq.com> Date: Sun, 28 Jul 2024 18:29:50 +0800 Subject: [PATCH] :rocket: feat(init): init --- .../cn/bunny/common/generator/NewCodeGet.java | 19 ++--- .../cn/bunny/entity/system/user/User.java | 57 +++++---------- .../cn/bunny/entity/system/user/Userinfo.java | 36 ++++++++++ pom.xml | 7 -- service/pom.xml | 29 ++++++-- .../service/controller/UserController.java | 42 +++++++++++ .../controller/UserinfoController.java | 36 ++++++++++ .../cn/bunny/service/mapper/UserMapper.java | 18 +++++ .../bunny/service/mapper/UserinfoMapper.java | 18 +++++ .../cn/bunny/service/service/UserService.java | 31 +++++++++ .../service/service/UserinfoService.java | 16 +++++ .../service/service/impl/UserServiceImpl.java | 48 +++++++++++++ .../service/impl/UserinfoServiceImpl.java | 20 ++++++ .../src/main/resources/application-dev.yml | 16 ++++- .../src/main/resources/application-prod.yml | 16 ++++- service/src/main/resources/application.yml | 69 ++++++++++++++----- .../src/main/resources/mapper/UserMapper.xml | 16 +++++ .../main/resources/mapper/UserinfoMapper.xml | 17 +++++ .../service/impl/UserServiceImplTest.java | 29 ++++++++ 19 files changed, 451 insertions(+), 89 deletions(-) create mode 100644 dao/src/main/java/cn/bunny/entity/system/user/Userinfo.java create mode 100644 service/src/main/java/cn/bunny/service/controller/UserController.java create mode 100644 service/src/main/java/cn/bunny/service/controller/UserinfoController.java create mode 100644 service/src/main/java/cn/bunny/service/mapper/UserMapper.java create mode 100644 service/src/main/java/cn/bunny/service/mapper/UserinfoMapper.java create mode 100644 service/src/main/java/cn/bunny/service/service/UserService.java create mode 100644 service/src/main/java/cn/bunny/service/service/UserinfoService.java create mode 100644 service/src/main/java/cn/bunny/service/service/impl/UserServiceImpl.java create mode 100644 service/src/main/java/cn/bunny/service/service/impl/UserinfoServiceImpl.java create mode 100644 service/src/main/resources/mapper/UserMapper.xml create mode 100644 service/src/main/resources/mapper/UserinfoMapper.xml create mode 100644 service/src/test/java/cn/bunny/service/service/impl/UserServiceImplTest.java diff --git a/common/common-generator/src/main/java/cn/bunny/common/generator/NewCodeGet.java b/common/common-generator/src/main/java/cn/bunny/common/generator/NewCodeGet.java index 27d0fe9..9b2bfef 100644 --- a/common/common-generator/src/main/java/cn/bunny/common/generator/NewCodeGet.java +++ b/common/common-generator/src/main/java/cn/bunny/common/generator/NewCodeGet.java @@ -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 customFile = new HashMap<>(); - // // 配置DTO(需要的话)但是需要有能配置Dto的模板引擎,比如freemarker,但是这里我们用的VelocityEngine,因此不多作介绍 - // customFile.put(outputDir, "/src/main/resources/templates/entityDTO.java.ftl"); - // consumer.customFile(customFile); - // }) - .execute(); + }).execute(); } } diff --git a/dao/src/main/java/cn/bunny/entity/system/user/User.java b/dao/src/main/java/cn/bunny/entity/system/user/User.java index 33c086d..5cb453f 100644 --- a/dao/src/main/java/cn/bunny/entity/system/user/User.java +++ b/dao/src/main/java/cn/bunny/entity/system/user/User.java @@ -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; /** *

- * 用户信息 + * *

* * @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; } diff --git a/dao/src/main/java/cn/bunny/entity/system/user/Userinfo.java b/dao/src/main/java/cn/bunny/entity/system/user/Userinfo.java new file mode 100644 index 0000000..7a985e1 --- /dev/null +++ b/dao/src/main/java/cn/bunny/entity/system/user/Userinfo.java @@ -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; + +/** + *

+ * + *

+ * + * @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; +} diff --git a/pom.xml b/pom.xml index 84a278c..0457bcb 100644 --- a/pom.xml +++ b/pom.xml @@ -40,7 +40,6 @@ 2.2 3.1 5.1.0 - 4.3.1 @@ -79,12 +78,6 @@ HikariCP ${HikariCP.version} - - - com.baomidou - dynamic-datasource-spring-boot3-starter - ${dynamic.datasource.version} - com.github.xiaoymin diff --git a/service/pom.xml b/service/pom.xml index a13047f..3a46a06 100644 --- a/service/pom.xml +++ b/service/pom.xml @@ -55,16 +55,31 @@ org.aspectj aspectjweaver - - - com.baomidou - dynamic-datasource-spring-boot3-starter - - + org.apache.shardingsphere shardingsphere-jdbc-core-spring-boot-starter - 5.2.1 + 5.1.1 + + + commons-io + commons-io + 2.15.1 + + + org.apache.calcite.avatica + avatica-core + 1.22.0 + + + org.apache.calcite + calcite-core + 1.32.0 + + + org.apache.commons + commons-collections4 + 4.5.0-M2 diff --git a/service/src/main/java/cn/bunny/service/controller/UserController.java b/service/src/main/java/cn/bunny/service/controller/UserController.java new file mode 100644 index 0000000..cc926a9 --- /dev/null +++ b/service/src/main/java/cn/bunny/service/controller/UserController.java @@ -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.*; + +/** + *

+ * 前端控制器 + *

+ * + * @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> queryPage(@PathVariable Integer page, @PathVariable Integer limit) { + Page parParams = new Page<>(page, limit); + PageResult vo = userService.queryPage(parParams); + return Result.success(vo); + } + + @Operation(summary = "添加用户", description = "添加用户") + @PostMapping("addUser") + public Result addUser(@RequestBody User user) { + userService.addUser(user); + return Result.success(); + } +} diff --git a/service/src/main/java/cn/bunny/service/controller/UserinfoController.java b/service/src/main/java/cn/bunny/service/controller/UserinfoController.java new file mode 100644 index 0000000..f7ad205 --- /dev/null +++ b/service/src/main/java/cn/bunny/service/controller/UserinfoController.java @@ -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; + +/** + *

+ * 前端控制器 + *

+ * + * @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 addUserinfo(@RequestBody Userinfo userInfo) { + userinfoService.save(userInfo); + return Result.success(); + } +} diff --git a/service/src/main/java/cn/bunny/service/mapper/UserMapper.java b/service/src/main/java/cn/bunny/service/mapper/UserMapper.java new file mode 100644 index 0000000..b46ded9 --- /dev/null +++ b/service/src/main/java/cn/bunny/service/mapper/UserMapper.java @@ -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; + +/** + *

+ * Mapper 接口 + *

+ * + * @author Bunny + * @since 2024-07-28 + */ +@Mapper +public interface UserMapper extends BaseMapper { + +} diff --git a/service/src/main/java/cn/bunny/service/mapper/UserinfoMapper.java b/service/src/main/java/cn/bunny/service/mapper/UserinfoMapper.java new file mode 100644 index 0000000..bf4ddbf --- /dev/null +++ b/service/src/main/java/cn/bunny/service/mapper/UserinfoMapper.java @@ -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; + +/** + *

+ * Mapper 接口 + *

+ * + * @author Bunny + * @since 2024-07-28 + */ +@Mapper +public interface UserinfoMapper extends BaseMapper { + +} diff --git a/service/src/main/java/cn/bunny/service/service/UserService.java b/service/src/main/java/cn/bunny/service/service/UserService.java new file mode 100644 index 0000000..a3ff044 --- /dev/null +++ b/service/src/main/java/cn/bunny/service/service/UserService.java @@ -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; + +/** + *

+ * 服务类 + *

+ * + * @author Bunny + * @since 2024-07-28 + */ +public interface UserService extends IService { + /** + * * 查询所有用户 + * + * @param parParams 分页参数 + * @return 分页结果 + */ + PageResult queryPage(Page parParams); + + /** + * * 添加用户 + * + * @param user 添加用户 + */ + void addUser(User user); +} diff --git a/service/src/main/java/cn/bunny/service/service/UserinfoService.java b/service/src/main/java/cn/bunny/service/service/UserinfoService.java new file mode 100644 index 0000000..3127f9f --- /dev/null +++ b/service/src/main/java/cn/bunny/service/service/UserinfoService.java @@ -0,0 +1,16 @@ +package cn.bunny.service.service; + +import cn.bunny.entity.system.user.Userinfo; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author Bunny + * @since 2024-07-28 + */ +public interface UserinfoService extends IService { + +} diff --git a/service/src/main/java/cn/bunny/service/service/impl/UserServiceImpl.java b/service/src/main/java/cn/bunny/service/service/impl/UserServiceImpl.java new file mode 100644 index 0000000..0c2b6ef --- /dev/null +++ b/service/src/main/java/cn/bunny/service/service/impl/UserServiceImpl.java @@ -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; + +/** + *

+ * 服务实现类 + *

+ * + * @author Bunny + * @since 2024-07-28 + */ +@Service +public class UserServiceImpl extends ServiceImpl implements UserService { + + /** + * * 查询所有用户 + * + * @param parParams 分页参数 + * @return 分页结果 + */ + @Override + public PageResult queryPage(Page parParams) { + Page page = page(parParams); + return PageResult.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); + } +} diff --git a/service/src/main/java/cn/bunny/service/service/impl/UserinfoServiceImpl.java b/service/src/main/java/cn/bunny/service/service/impl/UserinfoServiceImpl.java new file mode 100644 index 0000000..523144b --- /dev/null +++ b/service/src/main/java/cn/bunny/service/service/impl/UserinfoServiceImpl.java @@ -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; + +/** + *

+ * 服务实现类 + *

+ * + * @author Bunny + * @since 2024-07-28 + */ +@Service +public class UserinfoServiceImpl extends ServiceImpl implements UserinfoService { + +} diff --git a/service/src/main/resources/application-dev.yml b/service/src/main/resources/application-dev.yml index 8021204..fd3bc79 100644 --- a/service/src/main/resources/application-dev.yml +++ b/service/src/main/resources/application-dev.yml @@ -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" diff --git a/service/src/main/resources/application-prod.yml b/service/src/main/resources/application-prod.yml index 8021204..fd3bc79 100644 --- a/service/src/main/resources/application-prod.yml +++ b/service/src/main/resources/application-prod.yml @@ -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" diff --git a/service/src/main/resources/application.yml b/service/src/main/resources/application.yml index cd246c1..f02052d 100644 --- a/service/src/main/resources/application.yml +++ b/service/src/main/resources/application.yml @@ -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: diff --git a/service/src/main/resources/mapper/UserMapper.xml b/service/src/main/resources/mapper/UserMapper.xml new file mode 100644 index 0000000..26207a4 --- /dev/null +++ b/service/src/main/resources/mapper/UserMapper.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + id, uname + + + diff --git a/service/src/main/resources/mapper/UserinfoMapper.xml b/service/src/main/resources/mapper/UserinfoMapper.xml new file mode 100644 index 0000000..84f821b --- /dev/null +++ b/service/src/main/resources/mapper/UserinfoMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + id, username, age + + + diff --git a/service/src/test/java/cn/bunny/service/service/impl/UserServiceImplTest.java b/service/src/test/java/cn/bunny/service/service/impl/UserServiceImplTest.java new file mode 100644 index 0000000..205cf12 --- /dev/null +++ b/service/src/test/java/cn/bunny/service/service/impl/UserServiceImplTest.java @@ -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); + } +} \ No newline at end of file