MP 分页插件
配置类 MybatisPlusConfig
package mybatis.cn.config;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MybatisPlusConfig {
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
}
用法
@Test
public void testSelectByPage() {
System.out.println("===========按条件查询============");
QueryWrapper wrapper = new QueryWrapper();
wrapper.eq("name", "七仙女");
wrapper.orderByAsc("id");
IPage<Persons> page = new Page<>(1, 3);
IPage<Persons> personsIPage = personsMapper.selectPage(page, wrapper);
personsIPage.getRecords().forEach(System.out::println);
System.out.println("当前分页总页数===>" + personsIPage.getPages());
System.out.println("总条数===>" + personsIPage.getTotal());
}