1.mybatis-plus版本必须超过3.4.x
2.使用SSMP技术对Mapper类实现自动封装实现 可以参考我的 简单CURD操作mapper自动实现
3.对Mybatis-plus配置拦截器 这样你的Page类才能真正生效limit 实现分页
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;
//MybatisPlus拦截器
@Configuration
public class MPConfiguration {
@Bean
public MybatisPlusInterceptor setInterceptor(){
MybatisPlusInterceptor interceptor=new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
return interceptor;
}
}
4.进行测试结果
//@Autowired
//Private Mapper mapper ** 自己补充上去
@Test
public void selectPage(){
IPage page=new Page(1,3);
mapper.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("数据:\n"+page.getRecords());
}