//This is my controller
@RequestMapping("/getList")
public ModelAndView getList(@RequestParam(value="page",required=false) Integer page,Model model,@RequestParam(value="page_size",required=false) Integer page_size){
page=0;
page_size=4;
List<Employee> empList = empService.getEmpList1(page,page_size);
Employee emp=new Employee();
model.addAttribute("employee", emp);
return new ModelAndView("empList", "empList", empList);
}
//This is my Sql Query........
select * from EmpDetails LIMIT +page+","+page_size;
//This is my jsp.......for next button.....
<a href="/getList?page=${page}">Next:</a>
通过使用此代码,我在一个页面中获取员工的记录(0-4)。 我的问题是当我点击下一个按钮时,员工的记录(4-8)必须显示在其他页面中。你能告诉我如何编写代码吗?
答案 0 :(得分:0)
您不应在方法中为page
和page_size
变量分配严格的值。而不是这个,你应该从传递给方法的参数中获取值。
@RequestMapping("/getList")
public ModelAndView getList(@RequestParam(value="page",required=false) Integer page,Model model,@RequestParam(value="page_size",required=false) Integer page_size){
List<Employee> empList = empService.getEmpList1(page,page_size);
Employee emp=new Employee();
model.addAttribute("employee", emp);
return new ModelAndView("empList", "empList", empList);
}
当然,如果您的page
和page_size
是可选的,那么您必须检查是否传递了值。如果没有,那么你必须指定一些默认值。
答案 1 :(得分:0)
试试此代码
@RequestMapping("/getList")
public String getList(@RequestParam(value = "page", required = false) Integer page, Model model,
@RequestParam(value = "page_size", required = false) Integer page_size) {
if (page == null) {
page = 0;
}
if (page_size == null) {
page_size = 4;
}
List<Employee> empList = empService.getEmpList1(page, page_size);
Employee emp = new Employee();
model.addAttribute("employee", emp);
model.addAttribute("empList", empList);
model.addAttribute("page", page);
model.addAttribute("page_size", page_size);
return "empList";
}
//This for next button in jsp..... Try and let me know if this link work?
<a href="getList?page=${page+1}&page_size=${page_size}">Next:</a>
//This is my Sql Query........
recordStart = page * page_size;
select * from EmpDetails LIMIT +recordStart+","+page_size;