当我们使用layui 开启分页时,即
page:true
向服务器发起请求时,http头部信息中url为(以我项目为例):
http://localhost:8888/CEIS_war_exploded/student/querybypage?page=1&limit=10
注意page 和 limit 参数,page为当前页面序号,limit为当前页面大小。所以我们只需要拿到这两个参数,进行分页操作。
下面给出我的例子,
StudentMapper:
List<Student> queryStudentByPage(int startIndex,int pageSize);
StudentMapper.xml:
<select id="queryStudentByPage" resultType="student" parameterType="int">
select * from student limit #{param1},#{param2}
</select>
StudentController:
@RequestMapping("/querybypage")
@ResponseBody
public String queryStudentByPage(int page,int limit) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
List<Student> studentList = studentService.queryStudentByPage(limit*(page-1),limit);
return mapper.writeValueAsString(studentList);
}