踩坑系列–使用Pagehelper失效问题
这是pom.xml:
<!--pageHelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.5</version>
</dependency>
这是Service:
@Override
public Page<Employee> findall(int pageNum,int pageSize) {
Page<Employee> page = PageHelper.startPage(pageNum, pageSize);
employeeDao.findall();
return page;
}
这是Controller:
@RequestMapping("/empall/{start}/{pagesum}")
public String findall(Model model,@PathVariable int start,@PathVariable int pagesum) {
Page<Employee> collection = employeeService.findall(start,pagesum);
System.out.println(collection);
model.addAttribute("empall", collection);
return "emps/list";
}
看了很久,就是没问题
后来…
总算解决了,我的天!!!
完整配置如下:
import com.github.pagehelper.PageInterceptor;
import com.github.pagehelper.autoconfigure.PageHelperProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@EnableConfigurationProperties(PageHelperProperties.class)
@Configuration
public class PageInterceptorConfig {
@Autowired
private PageHelperProperties properties;
@Bean
public PageInterceptor pageInterceptor() {
PageInterceptor pageInterceptor = new PageInterceptor();
pageInterceptor.setProperties(properties.getProperties());
return pageInterceptor;
}
}
yaml配置:
pagehelper:
helperDialect: mysql
reasonable: true #开启优化,如果开启优化,在分页页码结果没有数据的时候,会显示有数据的页码数据
supportMethodsArguments: true #是否支持接口参数来传递分页参数,默认false
pageSizeZero: false #pageSize=0 返回所有
params: count=countSql
大功告成~!!!
如有侵权,请联系我~~~