分页查询
1.最简单的例子:
根据班级做分页查询
select * from student where class=?
limit beginIndex,pageSize
班级只是一个条件项,和我们说的分页查询关系不大;
从前台需要传到后台的参数分别是班级class和页数page,而每页的数据条数pageSize是固定的。这里我们假设每页条数pageSize为5.
为了方便mapper层接收参数,我们可以在控制层接收到参数class,page封装到map集合中
public class StudentController{
@Autowired
private StudentService studentService;
@responseBody
@requestMapping("seletStudentByClass")
public List<Student> selectStudentByClass(String class,int page){
Map<String,Object> map = new HashMap<String,Object>();
map.put("class",class);
map.put("beginIndex",(page-1)*5);
map.put("pageSize",5);
return serviceStudent.selectStudent(map);//把查询到的数据存放到list集合
}
}
以后见到别的方法会接着更新