概念不做介绍,直接上代码:
1.pom文件中引入依赖:
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.1.6</version>
</dependency>
2.编写mapper文件:
<select id="getAllProject" resultMap="BaseResultMap">
select * from project
</select>
3.在代码中使用:
public Map queryProjectByPage(Map map) {
if (map.get("pageNum") != null && map.get("pageSize") != null) {
int pageNum = MapUtility.getMapInt(map, "pageNum");
int pageSize = MapUtility.getMapInt(map, "pageSize");
PageHelper.startPage(pageNum, pageSize);
}
List<Project> query = projectMapper.getAllProject();
PageInfo<Project> pageInfo = new PageInfo<>(query);
return pageInfo;
}