@Bean public PageInterceptor pageInterceptor(){ PageInterceptor pageInterceptor = new PageInterceptor(); Properties p = new Properties(); p.setProperty("offsetAsPageNum", "true"); p.setProperty("rowBoundsWithCount", "true"); p.setProperty("reasonable", "false"); p.setProperty("pageSizeZero", "true"); pageInterceptor.setProperties(p); return pageInterceptor; }
@Bean( name = {"sqlSessionFactory"} ) public SqlSessionFactoryBean sqlSessionFactory(@Qualifier("dataSourceRouter") DataSource dataSourceRouter){ ... ... sqlSessionFactory.setPlugins(new Interceptor[]{this.pageInterceptor()}); ... ... return sqlSessionFactory; }
基本使用示例
推荐使用PageHelper.startPage方式:
1 2 3 4 5 6
public PageInfo<ThreedutyCheckRecord> findByUnitCode(String unitCode, int pageNum, int pageSize, String orderBy){ PageHelper.<ThreedutyCheckRecord>startPage(pageNum, pageSize, orderBy); List<ThreedutyCheckRecord> result = threedutyCheckRecordMapper.findByUnitCode(unitCode); PageInfo<ThreedutyCheckRecord> page = new PageInfo<>(result); return page; }