1.在pom.xml中添加如下:
<properties>
<pagehelper-version>5.0.0</pagehelper-version>
<jsqlparser-version>0.9.5</jsqlparser-version>
</properties>
<!--pagehelper-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>${pagehelper-version}</version>
</dependency>
<!-- pagehelper的依赖包:jsqlparser -->
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>${jsqlparser-version}</version>
</dependency>
2.在spring-mybatis中添加如下
<!--pageHelper-->
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageInterceptor">
<property name="properties">
<!--使用下面的方式配置参数,一行配置一个 -->
<value>
helperDialect=postgresql
reasonable=true
supportMethodsArguments=true
params=count=countSql
autoRuntimeDialect=true
</value>
</property>
</bean>
</array>
</property>
3.controller
@RequestMapping("/test")
public List<User> getList(int page,int size){
List<User> list = userService.test();
PageHelper.startPage(page,size);
PageInfo<Users> page = new PageInfo<Users>(list);
System.out.println("总数量:" + page.getTotal());
System.out.println("当前页查询:" + page.getList());
System.out.println("总页:" + page.getPages());
}
4.service
public List<User> test(){
List<User> list = userMapper.getUserList();
return list;
}
5.UserMapper
List<User> getUserList();
6.mapper.xml
<select id="getUserList" resultType="com.entity.User">
select * from user
</select>
PageHelper使用demo
最新推荐文章于 2022-07-21 15:48:32 发布