PageHelper的使用(maven项目中)
- 在pop.xml中导入pagehelper所需的依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.10</version>
</dependency>
2.在mybatis-config.xml中添加该插件(注意要加在标签之后,否则会报错)
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor">
</plugin>
</plugins>
-
在controller包下使用pagehelper插件
- 其中Mapper(相当于Dao)包下的接口及对应的sql语句写法(例子)
List<Student> getAllStudent();
<select id="getAllStudent" resultType="Student">
select * from ssm_crud.Student
</select>
2. Controller中使用方法
@RequestMapping("/findallemp")
//cp表示当前页,default默认当前页为第一页
public String findall(@RequestParam(value = "cp",defaultValue = "1") Integer currentpage, Model model){
/*引入pagehelper插件
* 在查询之前只需要调用,传入页码,以及每页的大小*/
PageHelper.startPage(currentpage,5);
/*startpage 后面紧跟的这个查询就是一个分页查询*/
/*获取到所有用户*/
List<Dept> deptList = deptService.selectAll();
//封装详细的分页信息,包括查询数据、显示的页数
PageInfo page = new PageInfo(deptList,5);
model.addAttribute("list",page);
return "emplist";
}
需要注意的问题:
servlet-api相关的依赖需要高于3.0
更多推荐
PageHelper的使用(maven项目中)
发布评论