StudySpringBoot01ApplicationTests.java
2.0 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package com.example.studyspringboot01;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.studyspringboot01.dao.UserDao;
import com.example.studyspringboot01.domain.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.ArrayList;
import java.util.List;
@SpringBootTest
class StudySpringBoot01ApplicationTests {
@Autowired
private UserDao userDao;
//查询所有
@Test
public void selectAllTest(){
List<User> userList = userDao.selectList(null);
userList.forEach(s -> System.out.println(s));
}
//新增
@Test
public void save(){
User user = new User();
user.id = 1;
user.username = "dingxiongchao";
user.password = "223344";
userDao.insert(user);
}
//删除
@Test
public void delete(){
userDao.deleteById(123);
}
//修改
@Test
public void update(){
User user = new User();
user.id = 13;
user.username = "1333";
user.password = "1343";
userDao.updateById(user);
}
//查询单个
@Test
public void selectById(){
userDao.selectById(122);
}
//分页查询
@Test
public void page(){
Page page = new Page(1,2);
Page page1 = userDao.selectPage(page, null);
System.out.println("分页查询,当前是多少页:"+ page1.getCurrent());
System.out.println("分页查询,一页能查询几条数据:"+ page1.getSize());
System.out.println("分页查询,一共多少页:"+ page1.getPages());
System.out.println("分页查询,一共多少条数据:"+ page1.getTotal());
System.out.println("分页查询,当前页显示数据:" + page1.getRecords());
}
//多选删除
@Test
public void deleteByIds(){
List<Integer> list = new ArrayList<>();
list.add(4);
list.add(5);
list.add(9);
userDao.deleteBatchIds(list);
}
}