Mad God told Java: https://www.bilibili.com/video/BV17E411N7KN?p=10 Tutorial Notes
1. User request
@Test
public void testSelectById(){
User user = userMapper.selectById(2L);
System.out.println(user);
}
2. Multiple users request
@Test
public void testSelectByBatchId(){
List<User> users = userMapper.selectBatchIds(Arrays.asList(1, 2, 3));
users.forEach(System.out::println);
}
III request conditions (1) the use of the map operation
@Test
public void testSelect(){
HashMap<String, Object> map = new HashMap<>();
map.put("name","night");
map.put("age",1);
List<User> users = userMapper.selectByMap(map);
users.forEach(System.out::println);
}
Fourth, a strange request
Pagling is widely used on the website, as if you can spend the following methods
-
Practical bribery with an initial limit
-
Use the third part of the plugin with PageHelper
-
Built-in Mybatis-Plus plugin for Pages
Using the Mybatis-Plus Paging Plugin:
1. Set up the Interceptor component (importer-pages-in plugin)
// плагин -плита -ин
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
2. Use the Page object directly
@Test
public void testPage(){
// Параметр 1: текущая страница; параметр 2: размер страницы
Page<User> page = new Page<>(2, 3);
userMapper.selectPage(page,null);
page.getRecords().forEach(System.out::println);
System.out.println(page.getTotal());
}