Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.mybatis;
import com.mybatis.mapper.UserMapper;
import com.mybatis.model.Context;
import com.mybatis.model.User;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.TransactionIsolationLevel;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@SpringBootTest
class MybatisApplicationTests {
private static final AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext("application.yml");
@Autowired
DataSource dataSource;
@Autowired
UserMapper userMapper;
@Test
void contextLoads() throws SQLException {
Context context = new Context("123","阿萨德");
User user = new User("test","男",context);
userMapper.insert(user);
}
@Test
void batchInsert(){
List<User> users = new ArrayList<User>();
for(int i=0;i<2;i++){
Context context = new Context("context"+i,"lowww"+i);
User user = new User("名字"+i,"男"+i,context);
users.add(user);
}
boolean isSuccess = userMapper.batchInsert(users);
}
}