package com.ag;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import com.ag.demo.mapper.StudentMapper;
import com.ag.demo.pojo.Student;
import com.ag.until.MybatisBatchUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

@Component
public class TestService {
    @Autowired
    StudentMapper studentMapper;
    @Autowired
    MybatisBatchUtil mybatisBatchUtil;

    public void run02(org.json.JSONObject param, HttpServletResponse response, HttpServletRequest request) {
        List<Student> students = new ArrayList<>();
        for (int i = 0; i < 1000; i++) {
            Student student = new Student();
            student.setsId(IdUtil.simpleUUID());
            student.setName("test");
            student.setAge(18);
            student.setSex("男");
            students.add(student);
        }
        mybatisBatchUtil.batchUpdateOrInsert(students,StudentMapper.class,(item,mapper)->mapper.insert(item));
    }
}
