pagehelper5.0使用的拦截器是PageInterceptor,pagehelper4.0使用的拦截器是PageHelper;而且5.0的版本去除了sqlsource模块的好几个类OrderByStaticSqlSource、PageSqlSource、PageRawSqlSource、PageStaticSqlSource、PageDynamicSqlSource、PageProviderSqlSource,pagehelper4.0版本切到pagehelper5.0需要注意这个问题。下面分别讲解springboot配置pagehelper5.0和4.0的版本,详细的配置见码云上的代码工程:freemarkerDemo
引入pagehelper-spring-boot-starter采用的是pagehelper5.0版本
com.github.pagehelper
pagehelper-spring-boot-starter
1.2.5
//localhost:8080/list?pageNum=1&pageSize=11
@RequestMapping("/list")
public String list(Model model, @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
@RequestParam(value = "pageSize", defaultValue = "2") int pageSize) {
PageHelper.startPage(pageNum, pageSize);//pageNum页码,pageSize每页大小
List list = userService.selectAllUsers();
PageInfo page = new PageInfo(list);
model.addAttribute("page", page);
return "content";
}
com.github.pagehelper
pagehelper
4.1.5
第一步:application.properties文件增加一条配置
mybatis.config-location= classpath:mybatis-config.xml
第二步:在mybatis-config.xml配置拦截器
@SpringBootApplication
@ComponentScan(basePackages = {"com.pingan.core"})
@Slf4j
public class App {
public static void main(String[] args) throws Exception {
SpringApplication.run(App.class, args);
}
@Bean
public PageHelper pageHelper() {
PageHelper pageHelper = new PageHelper();
Properties properties = new Properties();
properties.setProperty("offsetAsPageNum","true");
properties.setProperty("rowBoundsWithCount","true");
properties.setProperty("reasonable","true");
properties.setProperty("dialect","oracle"); //配置mysql数据库的方言
pageHelper.setProperties(properties);
return pageHelper;
}
}
//localhost:8080/list?pageNum=1&pageSize=11
@RequestMapping("/list")
public String list(Model model, @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
@RequestParam(value = "pageSize", defaultValue = "2") int pageSize) {
PageHelper.startPage(pageNum, pageSize);//pageNum页码,pageSize每页大小
List list = userService.selectAllUsers();
PageInfo page = new PageInfo(list);
model.addAttribute("page", page);
return "content";
}