分页插件配置
MybatisPlusConfig
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MybatisPlusConfig {
/**
* 添加分页插件
*/
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
}
分页查询学生
测试
@Autowired
private StudentMapper studentMapper;
@Test
public void test() {
int current = 1; //当前页数
int size = 10; //当前展示数量
Page<StudentEntity> page = new Page<>(current, size);
studentMapper.selectPage(page, null);
System.out.println("当前页数:" + page.getCurrent());
System.out.println("当前展示数量:" + page.getSize());
System.out.println("总页数:" + page.getPages());
System.out.println("总数量:" + page.getTotal());
System.out.println("当前展示数据:" + page.getRecords());
}