MySQL功能测试-之应用工程

MySQL功能测试-之应用工程

  • 前言
  • pom.xml
  • application.yml 文件
  • common.vo 包
    • ResultVO
  • config 包
    • properties 包
      • DruidConfigProperty
      • DruidMonitorProperty
    • AutoFillMetaObjectHandler
    • DruidConfig
    • FluxConfiguration
    • MyBatisPlusConfig
  • controller 包
    • ClientController
    • DruidController
    • WebFluxController
  • entity 包
    • ClientEntity
  • exception 包
    • code 包
      • CRUDStatus
    • BizException
    • GlobalException
  • mapper 包
    • ClientMapper
  • service 包
    • impl 包
    • ClientService
  • DruidApplication
  • resource/mapper 包
    • ClientMapper.xml

前言

应用工程的建设,主要是为了支撑 MySQL 数据库的一些测试场景,例如:

  1. 应用实时写入数据库时,进行修改表结构,查看锁的情况。
  2. 应用实时写入数据库时,数据库增量备份/恢复测试。
  3. 应用实时写入数据库时,数据库主从切换脚本测试。等等…各种场景。

当前工程是在《SpringBoot【2】集成 MyBatis Plus》基础上,进行代码迭代开发的,MySQL 数据库相关测试功能所涉及应用仅此一个,故此应用后续会不断完善,也会同步更新此文档。

目前完成后的项目截图如下:
在这里插入图片描述

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><artifactId>spring-boot-starter-parent</artifactId><groupId>org.springframework.boot</groupId><version>2.3.12.RELEASE</version><relativePath /></parent><groupId>com.junjiu.springboot.druid</groupId><artifactId>junjiu-springboot-druid</artifactId><version>1.0-SNAPSHOT</version><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target><mysql.connector.java.version>8.0.28</mysql.connector.java.version><mybatis.plus.boot.starter.version>3.3.1</mybatis.plus.boot.starter.version><druid.version>1.2.13</druid.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-webflux</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-websocket</artifactId></dependency><!-- MySQL驱动依赖. --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>${mysql.connector.java.version}</version></dependency><!-- mybatis-plus 依赖https://baomidou.com/getting-started/--><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version> ${mybatis.plus.boot.starter.version} </version></dependency><!-- Druid --><dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>${druid.version}</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId></dependency><!-- lombok 依赖 --><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency><!-- 阿里巴巴 fastjson --><dependency><groupId>com.alibaba.fastjson2</groupId><artifactId>fastjson2</artifactId><version>2.0.25</version></dependency></dependencies></project>

application.yml 文件

# 端口
server:port: 5826spring:application:# 应用名称name: junjiu-springboot-druiddatasource:type: com.alibaba.druid.pool.DruidDataSourcedruid:driver-class-name: com.mysql.jdbc.Driverurl: jdbc:mysql://192.168.88.54:3306/ideadb?useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull&useSSL=falseusername: fid_ideapassword: 123456initial-size: 10max-active: 100min-idle: 10max-wait: 60000pool-prepared-statements: truemax-pool-prepared-statement-per-connection-size: 20time-between-eviction-runs-millis: 60000min-evictable-idle-time-millis: 300000max-evictable-idle-time-millis: 600000validation-query: SELECT 1 FROM DUAL# validation-query-timeout: 5000test-on-borrow: falsetest-on-return: falsetest-while-idle: trueconnection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000#filters: #配置多个英文逗号分隔(统计,sql注入,log4j过滤)filters: stat,wallstat-view-servlet:enabled: trueurl-pattern: /druid/*# 监控页面配置.
jj:druid:monitor:login-username: rootlogin-password: 123456reset-enable: false# mybatis plus 配置
mybatis-plus:global-config:db-config:logic-delete-value: 1logic-not-delete-value: 0mapper-locations: classpath*:/mapper/*Mapper.xmltype-aliases-package: com.junjiu.springboot.druid.entity

common.vo 包

ResultVO

package com.junjiu.springboot.druid.common.vo;import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;import java.io.Serializable;/*** program: junjiu-springboot-druid* ClassName: ResultVO* description: 定义统一响应 Vo** @author: 君九* @create: 2024-06-15 10:11* @version: 1.0**/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResultVO implements Serializable {private Integer code;private String message;private Object data;/*** 状态码*/enum Status {SUCCESS(200, "成功"),SERVER_ERROR(500, "服务器内部错误");private Integer code;private String message;Status(Integer code, String message) {this.code = code;this.message = message;}public Integer getCode() {return this.code;}public String getMessage() {return this.message;}}public static ResultVO success(String message) {return new ResultVO(Status.SUCCESS.code, message, null);}public static ResultVO success(String message, Object data) {return new ResultVO(Status.SUCCESS.code, message, data);}public static ResultVO error(String message) {return new ResultVO(Status.SERVER_ERROR.code, message, null);}public static ResultVO error(String message, Object data) {return new ResultVO(Status.SERVER_ERROR.code, message, data);}public static ResultVO error(Integer code, String message, Object data) {return new ResultVO(code, message, data);}public static ResultVO error(Integer code, String message) {return new ResultVO(code, message, null);}}

config 包

properties 包

DruidConfigProperty

package com.junjiu.springboot.druid.config.properties;import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;/*** program: junjiu-springboot-druid* ClassName: DruidConfigProperty* description:** @author: 君九* @create: 2024-05-26 13:19* @version: 1.0**/
@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "spring.datasource.druid")
public class DruidConfigProperty {private String url;private String username;private String password;private String driverClassName;private int initialSize;private int maxActive;private int minIdle;private int maxWait;private boolean poolPreparedStatements;private int maxPoolPreparedStatementPerConnectionSize;private int timeBetweenEvictionRunsMillis;private int minEvictableIdleTimeMillis;private int maxEvictableIdleTimeMillis;private String validationQuery;private boolean testWhileIdle;private boolean testOnBorrow;private boolean testOnReturn;private String filters;private String connectionProperties;}

DruidMonitorProperty

package com.junjiu.springboot.druid.config.properties;import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;/*** program: junjiu-springboot-druid* ClassName: DruidMonitorProperty* description:** @author: 君九* @create: 2024-05-26 13:27* @version: 1.0**/
@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "jj.druid.monitor")
public class DruidMonitorProperty {private String loginUsername;private String loginPassword;private String resetEnable;}

AutoFillMetaObjectHandler

package com.junjiu.springboot.druid.config;import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;import java.time.LocalDateTime;/*** program: junjiu-springboot-druid* ClassName: AutoFillMetaObjectHandler* description:** @author: 君九* @create: 2024-06-12 22:52* @version: 1.0**/
@Component
public class AutoFillMetaObjectHandler  implements MetaObjectHandler {/*** 新增数据时,自动填充创建时间+修改时间 为当前时间。* @param metaObject*/@Overridepublic void insertFill(MetaObject metaObject) {this.strictInsertFill(metaObject, "createdTime", LocalDateTime.class, LocalDateTime.now());this.strictInsertFill(metaObject, "updatedTime", LocalDateTime.class, LocalDateTime.now());}/*** 更新数据时,自动填充创建时间+修改时间 为当前时间。* @param metaObject*/@Overridepublic void updateFill(MetaObject metaObject) {this.strictInsertFill(metaObject, "updatedTime", LocalDateTime.class, LocalDateTime.now());}
}

DruidConfig

package com.junjiu.springboot.druid.config;import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import com.junjiu.springboot.druid.config.properties.DruidConfigProperty;
import com.junjiu.springboot.druid.config.properties.DruidMonitorProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;/*** program: junjiu-springboot-druid* ClassName: DruidConfig* description: Druid 配置文件** @author: 君九* @create: 2024-05-26 13:16* @version: 1.0**/
@Configuration
public class DruidConfig {@AutowiredDruidConfigProperty druidConfigProperty;@AutowiredDruidMonitorProperty druidMonitorProperty;/*** Druid 连接池配置*/@Beanpublic DruidDataSource dataSource() {DruidDataSource datasource = new DruidDataSource();datasource.setUrl(druidConfigProperty.getUrl());datasource.setUsername(druidConfigProperty.getUsername());datasource.setPassword(druidConfigProperty.getPassword());datasource.setDriverClassName(druidConfigProperty.getDriverClassName());datasource.setInitialSize(druidConfigProperty.getInitialSize());datasource.setMinIdle(druidConfigProperty.getMinIdle());datasource.setMaxActive(druidConfigProperty.getMaxActive());datasource.setMaxWait(druidConfigProperty.getMaxWait());datasource.setTimeBetweenEvictionRunsMillis(druidConfigProperty.getTimeBetweenEvictionRunsMillis());datasource.setMinEvictableIdleTimeMillis(druidConfigProperty.getMinEvictableIdleTimeMillis());datasource.setMaxEvictableIdleTimeMillis(druidConfigProperty.getMaxEvictableIdleTimeMillis());datasource.setValidationQuery(druidConfigProperty.getValidationQuery());datasource.setTestWhileIdle(druidConfigProperty.isTestWhileIdle());datasource.setTestOnBorrow(druidConfigProperty.isTestOnBorrow());datasource.setTestOnReturn(druidConfigProperty.isTestOnReturn());datasource.setPoolPreparedStatements(druidConfigProperty.isPoolPreparedStatements());datasource.setMaxPoolPreparedStatementPerConnectionSize(druidConfigProperty.getMaxPoolPreparedStatementPerConnectionSize());try {datasource.setFilters(druidConfigProperty.getFilters());} catch (Exception ex) {ex.printStackTrace();}datasource.setConnectionProperties(druidConfigProperty.getConnectionProperties());return datasource;}/*** JDBC操作配置*/@Beanpublic JdbcTemplate jdbcTemplate (@Autowired DruidDataSource dataSource){return new JdbcTemplate(dataSource) ;}/*** 配置 Druid 监控界面*/@Beanpublic ServletRegistrationBean statViewServlet(){ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(),"/druid/*");//设置控制台管理用户servletRegistrationBean.addInitParameter("loginUsername",druidMonitorProperty.getLoginUsername());servletRegistrationBean.addInitParameter("loginPassword",druidMonitorProperty.getLoginPassword());// 是否可以重置数据servletRegistrationBean.addInitParameter("resetEnable",druidMonitorProperty.getResetEnable());return servletRegistrationBean;}@Beanpublic FilterRegistrationBean statFilter(){//创建过滤器FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter());//设置过滤器过滤路径filterRegistrationBean.addUrlPatterns("/*");//忽略过滤的形式filterRegistrationBean.addInitParameter("exclusions","*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");return filterRegistrationBean;}}

FluxConfiguration

package com.junjiu.springboot.druid.config;import org.springframework.context.annotation.Configuration;import org.springframework.context.annotation.Bean;
import reactor.core.publisher.DirectProcessor;
import reactor.core.publisher.FluxSink;/*** program: junjiu-springboot-druid* ClassName: FluxConfiguration* description:** @author: 君九* @create: 2024-06-15 12:16* @version: 1.0**/
@Configuration
public class FluxConfiguration {@Beanpublic DirectProcessor<String> directProcessor() {return DirectProcessor.create();}@Beanpublic FluxSink<String> fluxSink(DirectProcessor<String> directProcessor) {return directProcessor.sink();}
}

MyBatisPlusConfig

package com.junjiu.springboot.druid.config;import com.baomidou.mybatisplus.core.config.GlobalConfig;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;/*** program: junjiu-springboot-druid* ClassName: MyBatisPlusConfig* description:** @author: 君九* @create: 2024-06-12 22:49* @version: 1.0**/
@Configuration
public class MyBatisPlusConfig {@Beanpublic PaginationInterceptor paginationInterceptor() {return new PaginationInterceptor();}/***  自动填充功能* @return*/@Beanpublic GlobalConfig globalConfig() {GlobalConfig globalConfig = new GlobalConfig();globalConfig.setMetaObjectHandler(new AutoFillMetaObjectHandler());return globalConfig;}}

controller 包

ClientController

package com.junjiu.springboot.druid.controller;import com.junjiu.springboot.druid.common.vo.ResultVO;
import com.junjiu.springboot.druid.entity.ClientEntity;
import com.junjiu.springboot.druid.service.ClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.codec.ServerSentEvent;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;import java.time.Duration;/*** program: junjiu-springboot-druid* ClassName: ClientController* description:** @author: 君九* @create: 2024-06-12 22:59* @version: 1.0**/
@RestController
@RequestMapping("/client")
public class ClientController {@Autowiredprivate ClientService clientService;/*** 测试添加数据.* @return*/@RequestMapping("/testAdd")public String testAdd() {ClientEntity clientEntity = new ClientEntity();clientEntity.setClientId(1001L);clientEntity.setNickName("九皇叔叔");clientEntity.setRealName("君九");clientEntity.setUserNo("JunJiu");clientEntity.setUserPassword("123456");clientService.save(clientEntity);return "Success.";}/*** 我当前做测试,传入 loop、threadSize 一定有值,不在校验了** @param loop 是否循环* @param threadSize 线程个数.* @return*/@GetMapping("/setAddRandomData/{loop}/{threadSize}")public ResultVO setAddRandomData(@PathVariable("loop") Boolean loop,@PathVariable("threadSize") Integer threadSize) {clientService.setAddRandomData(loop, threadSize);return ResultVO.success("操作成功.loop=" + loop);}}

DruidController

package com.junjiu.springboot.druid.controller;import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;/*** program: junjiu-springboot-druid* ClassName: DruidController* description:** @author: 君九* @create: 2024-05-26 13:32* @version: 1.0**/
@RestController
public class DruidController {@Resourceprivate JdbcTemplate jdbcTemplate;@Autowiredprivate DruidDataSource druidDataSource;/*** 测试 Druid* @return*/@GetMapping("/test")public String testDruid() {String sql = "select version()";String result = jdbcTemplate.queryForObject(sql, String.class);SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");return "Success.".concat(simpleDateFormat.format(new Date())).concat(":").concat(result);}/*** 测试连接池.*  查看 performance_schema.threads 情况.* @param size* @return*/@GetMapping("/mutix/{size}")public String testDruidMutix(@PathVariable("size") Integer size) {for(int k = 0; k < size; k++) {new Thread(() -> {String sql = "select '你也可以通过操作系统级别的资源限制来控制 MySQL 进程的内存使用情况。具体的操作方式会根据操作系统的不同而有所不同,比如在 Linux 中可以使用 ulimit 命令来设置进程的资源限制。'";String result = jdbcTemplate.queryForObject(sql, String.class);System.out.println(Thread.currentThread().getName() + ":" + result);}).start();}SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");return "Success.".concat(simpleDateFormat.format(new Date()));}
}

WebFluxController

package com.junjiu.springboot.druid.controller;import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;import java.time.Duration;/*** program: junjiu-springboot-druid* ClassName: WebFluxController* description:** @author: 君九* @create: 2024-06-15 11:26* @version: 1.0**/
@RestController
public class WebFluxController {@GetMapping("/data")public Flux<String> streamData() {// 模拟生成实时数据流return Flux.just("Data 1", "Data 2", "Data 3", "Data 4").delayElements(Duration.ofSeconds(1));}
}

entity 包

ClientEntity

package com.junjiu.springboot.druid.entity;import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;import java.io.Serializable;
import java.util.Date;/*** program: junjiu-springboot-druid* ClassName: ClientEntity* description:** @author: 君九* @create: 2024-06-12 22:55* @version: 1.0**/
@Data
@TableName("client")
public class ClientEntity implements Serializable {/*** -- 1 -* 客户表* create table client(*    id bigint not null primary key auto_increment comment '自增ID',*    client_id bigint not null comment 'ID编号',*    user_no varchar(30) comment '账号',*    user_password varchar(60) comment '密码',*    nick_name varchar(30) comment '昵称',*    real_name varchar(30) comment '真实姓名',*    created_time datetime default now() comment '创建时间',*    upated_time datetime default now() comment '更新时间'* );*/private Long id;private Long clientId;private String userNo;private String userPassword;private String nickName;private String realName;private Date createdTime;private Date updatedTime;}

exception 包

code 包

CRUDStatus

package com.junjiu.springboot.druid.exception.code;/*** program: junjiu-springboot-druid* ClassName: CRUDStatus* description: CRUD操作通用状态码.** @author: 君九* @create: 2024-06-15 10:09* @version: 1.0**/
public enum CRUDStatus {// 添加成功SUCCESS_INSERT(100001, "添加成功"),// 添加失败FAIL_INSERT(100002, "添加失败"),// 修改成功SUCCESS_UPDATE(100003, "修改成功"),// 修改失败FAIL_UPDATE(100004, "修改失败"),// 删除成功SUCCESS_DELETE(100005, "删除成功"),// 删除失败FAIL_DELETE(100006, "删除失败"),// 未查询到数据NOT_FOUND(100007, "未查询到数据"),// 非法数据信息ILLEGAL_ARGUMENT(100008, "非法数据信息");private Integer code;private String message;CRUDStatus(Integer code, String message) {this.code = code;this.message = message;}public Integer getCode() {return this.code;}public String getMessage() {return this.message;}}

BizException

package com.junjiu.springboot.druid.exception;import lombok.Data;/*** program: junjiu-springboot-druid* ClassName: BizException* description: 定义业务类统一异常类** @author: 君九* @create: 2024-06-15 10:08* @version: 1.0**/
@Data
public class BizException extends RuntimeException {private Integer code;private String message;public BizException(String message) {super(message);this.message = message;}public BizException(Integer code, String message) {this.code = code;this.message = message;}public BizException(String message, Exception exception) {super(message, exception);this.message = message;}public BizException(Integer code, String message, Exception exception) {super(message, exception);this.code = code;this.message = message;}
}

GlobalException

package com.junjiu.springboot.druid.exception;/*** program: junjiu-springboot-druid* ClassName: GlobalException* description:** @author: 君九* @create: 2024-06-15 10:08* @version: 1.0**/
public class GlobalException {
}

mapper 包

ClientMapper

package com.junjiu.springboot.druid.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.junjiu.springboot.druid.entity.ClientEntity;
import org.apache.ibatis.annotations.Mapper;/*** program: junjiu-springboot-druid* ClassName: ClientMapper.xml* description:** @author: 君九* @create: 2024-06-12 22:57* @version: 1.0**/
@Mapper
public interface ClientMapper extends BaseMapper<ClientEntity> {
}

service 包

impl 包

package com.junjiu.springboot.druid.service.impl;import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.junjiu.springboot.druid.entity.ClientEntity;
import com.junjiu.springboot.druid.exception.BizException;
import com.junjiu.springboot.druid.exception.code.CRUDStatus;
import com.junjiu.springboot.druid.mapper.ClientMapper;
import com.junjiu.springboot.druid.service.ClientService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;/*** program: junjiu-springboot-druid* ClassName: ClientServiceImpl* description:*  客户业务实现类.** @author: 君九* @create: 2024-06-12 22:58* @version: 1.0**/
@Service
public class ClientServiceImpl extends ServiceImpl<ClientMapper, ClientEntity> implements ClientService {private ThreadLocal<Thread> threadLocal = new ThreadLocal<>(); // ThreadLocal 存储每个线程private volatile boolean loop = true; // 用于控制线程循环的共享变量@Override@Transactional(rollbackFor = Exception.class)public void setAddRandomData(Boolean loop, Integer threadSize) {this.loop = loop; // 设置共享变量的初始值CompletableFuture<?>[] futures = new CompletableFuture[threadSize];if(loop) {for (int i = 0; i < threadSize; i++) {final int threadNumber = i + 1;CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {while (this.loop) {// 创建随机的 ClientEntity 对象ClientEntity client = new ClientEntity();client.setClientId(Thread.currentThread().getId()); // 设置随机的 clientIdclient.setUserNo(Thread.currentThread().getName()); // 将 userNo 设置为当前线程名称client.setUserPassword(generateRandomString(16)); // 生成随机密码client.setNickName("NickName_" + Thread.currentThread().getId()); // 设置昵称client.setRealName("RealName_" + Thread.currentThread().getId()); // 设置真实姓名try {// 将生成的 ClientEntity 插入数据库baseMapper.insert(client);} catch (Exception exception) {exception.printStackTrace();throw new BizException(CRUDStatus.FAIL_DELETE.getCode(), CRUDStatus.FAIL_INSERT.getMessage(), exception);}Random random = new Random();int randomData = random.nextInt(1000);try {Thread.sleep(randomData);} catch (InterruptedException e) {e.printStackTrace();}}});futures[i] = future.exceptionally(ex -> {// 异常处理if (ex.getCause() instanceof BizException) {throw (BizException) ex.getCause(); // 将 BizException 抛给父线程} else {// 其他异常,可以选择处理或包装成自定义异常throw new RuntimeException("Unexpected error occurred in thread " + threadNumber, ex);}});threadLocal.set(Thread.currentThread());}try {CompletableFuture.allOf(futures).get(); // 等待所有 CompletableFuture 完成} catch (InterruptedException | ExecutionException e) {// 处理异常// e.printStackTrace();System.out.println(e.getMessage());}} else {this.loop = false; // 设置 loop 为 false,停止所有线程的循环}}/*** 生成指定长度的随机字符串(仅用于示例,实际应用中需要更复杂的实现)* @param length 字符串长度* @return 随机字符串*/private String generateRandomString(int length) {String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";StringBuilder sb = new StringBuilder();Random random = new Random();for (int i = 0; i < length; i++) {int index = random.nextInt(characters.length());sb.append(characters.charAt(index));}return sb.toString();}}

ClientService

package com.junjiu.springboot.druid.service;import com.baomidou.mybatisplus.extension.service.IService;
import com.junjiu.springboot.druid.entity.ClientEntity;/*** program: junjiu-springboot-druid* ClassName: ClientService* description:*  客户端业务接口.** @author: 君九* @create: 2024-06-12 22:57* @version: 1.0**/
public interface ClientService extends IService<ClientEntity> {/*** 随机添加数据,用于模拟:应用实时添加数据情况,对 MySQL 数据库进行备份恢复、调整字段长度等场景。** --- 目标:* 1.根据传入的线程个数,开启多线程。* 2.产生随机等待时长,使线程等待后,在执行添加数据操作。* 3.可手动开启/暂停,数据入库。** @param loop 循环.* @param threadSize 线程个数.**/void setAddRandomData(Boolean loop, Integer threadSize);}

DruidApplication

package com.junjiu.springboot.druid;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;/*** program: junjiu-springboot-druid* ClassName: DruidApplication* description:** @author: 君九* @create: 2024-05-26 13:13* @version: 1.0**/
@SpringBootApplication
public class DruidApplication {public static void main(String[] args) {SpringApplication.run(DruidApplication.class);}
}

resource/mapper 包

ClientMapper.xml

<?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="com.junjiu.springboot.druid.mapper.ClientMapper"><!-- 通用查询映射结果 --><resultMap id="BaseResultMap" type="com.junjiu.springboot.druid.entity.ClientEntity"><id column="id" property="id" /><result column="client_id" property="clientId" /><result column="user_no" property="userNo" /><result column="user_password" property="userPassword" /><result column="nick_name" property="nickName" /><result column="real_name" property="realName" /><result column="created_time" property="createdTime" /><result column="updated_time" property="updatedTime" /></resultMap><!-- 通用查询结果列 --><sql id="Base_Column_List">id, client_id, user_no, user_password, nick_name, real_name, created_time, updated_time</sql></mapper>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/30830.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

操作系统之如何使用C语言完成SFJ和SRTJ,并完成他的甘特图

目录 前言 SFJ SRTJ 结束语 前言 不知不觉已经写博客一个月了&#xff0c;前段时间因为学业上的一些原因咕咕咕了&#xff0c;今天我又回来了。今天我给大家带来的是C语言代码完成的SFJ和SRTJ&#xff0c;并且带大家描述他的甘特图。如果有对SFJ和SRTJ不了解的小伙伴可以翻…

Flink Sql Redis Connector

经常做开发的小伙伴肯定知道用flink连接redis的时候比较麻烦&#xff0c;更麻烦的是解析redis数据&#xff0c;如果rdis可以普通数据库那样用flink sql连接并且数据可以像表格那样展示出来就会非常方便。 历时多天&#xff0c;我终于把flink sql redis connector写出来了&…

【C语言】手写学生管理系统丨附源码+教程

最近感觉大家好多在忙C语言课设~ 我来贡献一下&#xff0c;如果对你有帮助的话谢谢大家的点赞收藏喔&#xff01; 1. 项目分析 小白的神级项目&#xff0c;99%的程序员&#xff0c;都做过这个项目&#xff01; 掌握这个项目&#xff0c;就基本掌握 C 语言了&#xff01; 跳…

idea http client GET 请求 报503错误

idea 提供的 http client 插件&#xff0c;在 GET 请求时总是 报503 的错误&#xff0c;但请求URL可以在浏览器中正常访问。 GET localhost:8080/student Response file saved. > 2024-06-20T160906.503.html 有一种原因跟本地配置的代理有关&#xff0c;如下图。如果在…

大模型应用场景在哪?探索人工智能的无限可能

随着人工智能技术的飞速发展&#xff0c;大模型在自然语言处理、计算机视觉、推荐系统等领域取得了显著成果。这些大模型&#xff0c;如OpenAI的GPT-3、谷歌的BERT、百度的ERNIE等&#xff0c;不仅在学术界引起了巨大反响&#xff0c;也在产业界得到了广泛应用。本文将以大模型…

sqlcoder实践

背景 Defog llama-3 意义 翻译自然语言到sql&#xff0c;类似脑机接口&#xff0c;大模型重要应用领域 sql是数据库查询标准;关系数据库&#xff0c;工具(datax,sqoop&#xff0c;logstash,hive)&#xff0c;非关系数据库&#xff08;MongoDB&#xff0c;图数据库&#xff…

上新:NFTScan 正式上线 Bitcoin-brc20 浏览器!

近日&#xff0c;NFTScan 团队正式对外发布了 Bitcoin-brc20 浏览器&#xff0c;将为 Bitcoin 生态的 NFT 开发者和用户提供简洁高效的 NFT 数据搜索查询服务。作为比特币生态中最火热的标准之一&#xff0c;brc20 也吸引着广泛的关注。洞悉其巨大潜力&#xff0c;NFTScan 对 b…

协同编辑:只是在线协作这么简单吗?揭秘协同编辑的深层价值

经常很多朋友咨询&#xff0c;无忧企业文档是否支持协同编辑&#xff0c;首先肯定是支持的。但是&#xff0c;我发现很多人对于“协同编辑”的理解可能比较表面&#xff0c;仅仅停留在多人同时编辑一份文档的层面。实际上&#xff0c;协同编辑的功能远不止于此&#xff0c;它更…

两个方法,批量替换PPT中的字体

经常制作ppt的朋友可能会遇到需要批量替换字体的情况&#xff0c;如果我们想要更换ppt中的字体&#xff0c;今天分享PPT批量替换字体的两个方法。 方法一&#xff1a; 找到功能栏中的编辑选项卡&#xff0c;点击替换 – 替换字体&#xff0c;在里面选择我们想要替换的字体就可…

通过MindSpore API实现深度学习模型

快速入门 将相应的包逐一导入到项目中&#xff0c;这是制作项目的第一步。 import mindspore from mindspore import nn from mindspore.dataset import vision, transforms from mindspore.dataset import MnistDataset 处理数据集 先从网上下载对应的数据集文件,MindSpor…

《C++ Primer》导学系列:第 6 章 - 函数

6.1 函数基础 6.1.1 基本概念 函数是C程序的基本组成单元&#xff0c;用于将代码组织成可以复用的模块。函数通过函数名进行调用&#xff0c;并且可以接受参数和返回值。函数的定义包括函数头和函数体&#xff0c;其中函数头描述了函数的接口&#xff0c;函数体包含了具体的实…

最新OPPO 真我手机 一加手机 使用adb命令永久关闭系统更新教程

使用adb命令永久关闭系统更新 一、先了解手机系统二、Android 11 以下使用adb 命令永久关闭系统更新1、adb 官方下载2、小白开启 USB 调试模式教程&#xff08;熟手跳过&#xff09;三、Android 12 以上使用adb 命令永久关闭系统更新什么您还是不会弄&#xff01;赞赏我&#x…

MYSQL 四、mysql进阶 3(存储引擎)

mysql中表使用了不同的存储引擎也就决定了我们底层文件系统中文件的相关物理结构。 为了管理方便&#xff0c;人们把连接管理、语法解析、查询优化这些并不涉及真实数据存储的功能划分为 Mysql Server的功能&#xff0c;把真实存取数据的功能划分为存储引擎的功能&…

systemd的实现原理

systemd是现代Linux系统中的初始化系统和服务器管理器&#xff0c;而systemctl是用于与systemd交互的命令行工具。 systemd是一个守护进程&#xff0c;systemctl是命令行管理工具&#xff1a;systemd是用于管理Linux系统的初始化过程和后台服务的初始化系统&#xff0c;而syst…

Windows10 + fydeOS双系统!简单几步完成

前言 最近发现小伙伴对于fydeOS热情是真的不减&#xff0c;啧啧啧……今天闲来无事&#xff0c;就来讲讲双系统Windows10 fydeOS的安装方法吧&#xff01; Windows10 FydeOS双系统安装过程其实很简单&#xff0c;不过要建议先安装好Windows10系统。 虽然先安装好fydeOS之后…

SpringBootWeb 篇-入门了解 Vue 前端工程的创建与基本使用

&#x1f525;博客主页&#xff1a; 【小扳_-CSDN博客】 ❤感谢大家点赞&#x1f44d;收藏⭐评论✍ 文章目录 1.0 基于脚手架创建前端工程 1.1 基于 Vue 开发前端项目的环境要求 1.2 前端工程创建的方式 1.2.1 基于命令的方式来创建前端工程 1.2.2 使用图形化来创建前端工程 1.…

如何建立私域流量?私域流量怎么运营,一文读懂

当全网都在讨论私域流量&#xff0c;你是不是也有很多问号呢&#xff1f; 互联网高速发达&#xff0c;消费形式日新月异&#xff0c;跟不上时代就会被时代淘汰&#xff0c;接下来&#xff0c;我们就从3个层面深度讨论下私域流量究竟是什么&#xff1f;为什么要玩转私域流量&am…

【保姆级教程】Linux 基于 Docker 部署 MySQL 和 Nacos 并配置两者连接

一、Linux 部署 Docker 1.1 卸载旧版本&#xff08;如有&#xff09; sudo yum remove docker \docker-client \docker-client-latest \docker-common \docker-latest \docker-latest-logrotate \docker-logrotate \docker-engine1.2 安装 yum-utils 包 sudo yum install -y…

微信多开器

由于微信的限制&#xff0c;我们平时只能登录一个微信&#xff0c;要登录多个微信一般需要多台手机&#xff0c;很显然这种方法很费手机&#xff01;&#xff01;一个微信多开神器可以给你省下好几台手机钱&#xff0c;抓紧拉下来放手机里落灰http://www.xbydon.online/?p132 …

NetSuite 审批工作流与事务处理类型的限制关系

在最近的实践中&#xff0c;用户提出可否对Credit Memo与Vendor Prepayment Application两种事务处理类型进行审批参与&#xff0c;当提出来的时候我们并没有直接在系统中进行测试&#xff0c;而是以常规事务处理的角度认为可以满足客户的需求&#xff1b; 但在沙盒环境中讨论…