使用pageHelper插件+jqgrid实现分页(学习随笔,如有错漏之处,敬请指正)
1.使用pageHelper
附pagehelper使用文档:https://pagehelper.github.io/docs/
1.1导包:pagehelper.jar和jsqlparse.jar
pom.xml中导入约束(注意pageHelper包依赖了jsqlparse,所以不用重复导):
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.10</version>
</dependency>
首先要留意一下PageInfo对象中定义的成员变量
1.2在services层使用pagehelper
先贴代码:
services接口:
package com.springmvc.demo.services;
import java.util.List;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageInfo;
import com.springmvc.demo.entity.User;
public interface UserServices {
//返回值是pageInfo<查询实体类>(主要在controller使用),pagenum:查询第几页,size查询每页的条数,
//sidx是排序的列名,sord是排序规则(四参数均由jqgrid提供)
public PageInfo<User> userslist(Integer pagenum,Integer size,String sidx,String sord);
}
services实现类:
package com.springmvc.demo.services;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.springmvc.demo.entity.User;
import com.springmvc.demo.entity.UserExample;
import com.springmvc.demo.mapper.UserMapper;
@Service
public class UserServicesImpl implements