Mybatis-Plus Learning Notes (3) Run request

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);
    }

397fa562b32fc87c9c3c87da36de2a8d

2. Multiple users request

    @Test
    public void testSelectByBatchId(){
        List<User> users = userMapper.selectBatchIds(Arrays.asList(1, 2, 3));
        users.forEach(System.out::println);
    }

18433ff913caba235717679472c90cb2

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);
    }

25260f4d904bea54055cfe617bb291ad

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());
    }

35ecf46b6e612a09cc431bf16b318120

Leave a Comment