PageHelper的使用(maven项目中)

编程入门 行业动态 更新时间:2024-10-25 18:35:17

PageHelper的使用(maven项目中)

  1. 在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>
  1. 在controller包下使用pagehelper插件

    1. 其中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项目中)

本文发布于:2023-06-14 09:55:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1463690.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   PageHelper   maven

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!