`
kuailenanhaier
  • 浏览: 32666 次
社区版块
存档分类
最新评论

springboot添加PageHelper分页查询插件

 
阅读更多
springboot添加PageHelper分页查询插件

1、POM文件中引入PageHelper包
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.4</version>
</dependency>


2、在resources目录下创建mybatis-config.xml文件配置PageHelper分页查询插件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!-- 配置pageHelper分页查询插件 -->
<plugins>
        <plugin interceptor="com.github.pagehelper.PageInterceptor">
            <property name="helperDialect" value="mysql"/>
        </plugin>
    </plugins>
</configuration>


3、在application.properties中添加PageHelper插件
mybatis.configLocation=classpath:mybatis-config.xml


4、在controller层的方法中调用PageHelper分页查询
@RequestMapping(value="/pushList",method={RequestMethod.POST,RequestMethod.GET})
    public ModelAndView pushManageList(@RequestParam(defaultValue="1",required=true)Integer page)
    {
    //利用PageHelper进行分页查询
    //pageNum为当前页码;pageSize每页显示记录数;count=true则进行count查询总记录数
    PageHelper.startPage(page, 2,true);
   
        List<PushManageTaskInfo> pushList = pushManageTaskService.queryPushManageInfoList();
       
        PageInfo<PushManageTaskInfo> pageQuery=new PageInfo<PushManageTaskInfo>(pushList);
       
        ModelAndView mview=new ModelAndView("pushList");
        mview.addObject("pushList", pushList);
        mview.addObject("page",pageQuery);
        return mview; 
    }



5、前端页面分页查询
<a href="pushList?page=${page.firstPage}">第一页</a>
<a href="pushList?page=${page.prePage}">上一页</a>
<a href="pushList?page=${page.nextPage}">下一页</a>
<a href="pushList?page=${page.lastPage}">尾页</a>
当前第${page.pageNum}页&nbsp;&nbsp;&nbsp;&nbsp;一共${page.pages}页


最后用浏览器访问页面效果





  • 大小: 15.6 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics