( 简单操作,仅供初级练习,数据会丢失,工作不要用~!)
测试类:
package csgo;
import com.ruoyi.RuoYiApplication;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.traces.csgo.domain.APersonnelInfo;
import com.ruoyi.traces.csgo.service.APersonnelInfoService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplicationRunListener;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.BootstrapWith;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
@SpringBootTest(classes = RuoYiApplication.class)
@RunWith(SpringRunner.class)
public class APersonnelInfoConrollerTest {
@Autowired
APersonnelInfoService aPersonnelInfoService;
@Test
public void test2(){
ArrayList<APersonnelInfo> aPersonnelInfos = new ArrayList<>();
for (int i=0;i<=130000;i++){
// 生成唯一ID
String uuid = IdUtils.fastSimpleUUID();
// 实体类
APersonnelInfo aPersonnelInfo1 = new APersonnelInfo();
aPersonnelInfo1.setName("云飞");
aPersonnelInfo1.setGender("女");
aPersonnelInfo1.setAge(18L);
aPersonnelInfo1.setAddress("清南");
aPersonnelInfo1.setPhone("186117*8545");
aPersonnelInfo1.setUuidNum(uuid);
// 添加到集合
aPersonnelInfos.add(aPersonnelInfo1);
}
// list集合存储
int saves= aPersonnelInfoService.saveAPersonnelInfoList(aPersonnelInfos);
// 清除list集合
aPersonnelInfos.clear();
}
}
Mapper层:
int saveAPersonnelInfoList(@Param("list") ArrayList<APersonnelInfo> aPersonnelInfos);
Mapper.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.ruoyi.traces.csgo.mapper.APersonnelInfoMapper">
<resultMap id="APersonnelInfoResultMap" type="com.ruoyi.traces.csgo.domain.APersonnelInfo">
<id column="id" jdbcType="BIGINT" property="id"/>
<id column="name" jdbcType="VARCHAR" property="name"/>
<id column="gender" jdbcType="VARCHAR" property="gender"/>
<id column="age" jdbcType="BIGINT" property="age"/>
<id column="address" jdbcType="VARCHAR" property="address"/>
<id column="phone" jdbcType="VARCHAR" property="phone"/>
<id column="uuidNum" jdbcType="VARCHAR" property="uuidNum"/>
</resultMap>
<!-- 列表集合添加-->
<insert id="saveAPersonnelInfoOne" parameterType="com.ruoyi.traces.csgo.domain.APersonnelInfo">
insert into
a_personnel_info (name,gender,age,address,phone,uuidNum) values
(#{name},#{gender},#{age},#{address},#{phone},#{uuidNum})
</insert>
<insert id="saveAPersonnelInfoList" parameterType="java.util.List">
insert into
a_personnel_info (name,gender,age,address,phone,uuidNum) values
<foreach collection="list" item="item" index="index" separator=",">
(
#{item.name},
#{item.gender},
#{item.age},
#{item.address},
#{item.phone},
#{item.uuidNum}
)
</foreach>
</insert>
</mapper>
数据库:
DROP TABLE IF EXISTS `a_personnel_info`;
CREATE TABLE `a_personnel_info` (
`id` bigint NOT NULL AUTO_INCREMENT,
`name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '姓名',
`gender` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '性别',
`age` int NULL DEFAULT NULL COMMENT '年龄',
`address` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '地址',
`phone` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '手机号',
`uuidNum` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '唯一编码',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 130002 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '人员信息表Me' ROW_FORMAT = Dynamic;
SET FOREIGN_KEY_CHECKS = 1;