web123456

MybatisPlus' selectPage method

MybatisPlus' selectPage method

  • Method Description
  • Parameter description
  • Application examples

Method Description

The code is as follows (example):

// According to the entity conditions, query all records (and turn pages)
IPage<T> selectPage(IPage<T> page, @Param(Constants.WRAPPER) Wrapper<T> queryWrapper);

Parameter description

Parameter name describe
page Pagination query conditions (can be )
queryWrapper Entity object encapsulation operation class (can be null)

Application examples

// Pagination query, example: Two records per page, query the first page
@Test
public void testCommonSelect(){
    EntityWrapper<Employee> ew = new EntityWrapper<Employee>();
    List<Employee> result = employeeMapper.selectPage(new Page<>(1, 2),
            ew.between("id",1,20).eq("gender","F"));
    System.out.println(result);
 }

Note: selectPage uses EntityWrapper to filter out all data that meet the criteria, and thenAfter filteringThe data is paged and output according to the rules.