gpt4 book ai didi

java - 如何在 Spring MVC 3 中实现分页

转载 作者:IT老高 更新时间:2023-10-28 13:02:20 25 4
gpt4 key购买 nike

是否有任何开箱即用、易于实现的标准分页组件/标签库或代码示例可用于 Spring MVC 中的分页?

最佳答案

看看PagedListHolder和来自 org.springframework.beans.support 的其他类(class).

请参阅示例中的 JPetstore 以获取一些示例,例如在 SearchProductsController.java :

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
String keyword = request.getParameter("keyword");
if (keyword != null) {
if (!StringUtils.hasLength(keyword)) {
return new ModelAndView("Error", "message", "Please enter a keyword to search for, then press the search button.");
}
PagedListHolder productList = new PagedListHolder(this.petStore.searchProductList(keyword.toLowerCase()));
productList.setPageSize(4);
request.getSession().setAttribute("SearchProductsController_productList", productList);
return new ModelAndView("SearchProducts", "productList", productList);
}
else {
String page = request.getParameter("page");
PagedListHolder productList = (PagedListHolder) request.getSession().getAttribute("SearchProductsController_productList");
if (productList == null) {
return new ModelAndView("Error", "message", "Your session has timed out. Please start over again.");
}
if ("next".equals(page)) {
productList.nextPage();
}
else if ("previous".equals(page)) {
productList.previousPage();
}
return new ModelAndView("SearchProducts", "productList", productList);
}
}

关于java - 如何在 Spring MVC 3 中实现分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2245035/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com