[转]Springboot接口简单实现生成MySQL插入语句
在实际测试中,有这样一个需求场景,比如:在性能压力测试中,可能需要我们事先插入数据库中一些相关联的数据。
我们在实际测试中,遇到问题,需要事先在数据库中创建10000家门店,存在shop表中。关键字段(门店的编号6位数)。
分析:两种具体实现方案。
一、利用MySQL函数功能随机生成
二、使用springboot编写接口实现,并自动生成insert脚本保存本地。
本次实现以springboot接口实现此次目的:
pom.xml文件配置
<?xml version="1.0" encoding="UTF-8"?>4.0.0 org.springframework.boot spring-boot-starter-parent 2.1.1.RELEASE com.springbootDemo demo 0.0.1-SNAPSHOT demo Demo project for Spring Boot 1.8 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test org.projectlombok lombok 1.16.14 org.springframework.boot spring-boot-maven-plugin
main里面有默认启动类。
@RestController
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
编写接口实现类
@RequestMapping("/generateSql")
public static String insert(@RequestParam(required = false) int size) throws IOException {
// 开时时间
Long begin = new Date().getTime();
log.info("begin:{}",begin);
for (int i = 0; i >>>>>" + size;
}
启动主程序,调用接口