java 数据分页
分页逻辑
import lombok.Data;
/**
* User eric
* Date
* Email yq@aso.ren
*/
@Data
public class PageHelper
{
private int pageSize;
private int totalPage;
private int currentPage;
private String path = "";
public String getPageHTML()
{
totalPage = getTotalPage();
StringBuffer displayInfo = new StringBuffer();
if (totalPage != 0 && pageSize != 0)
{
if (currentPage > 1)
{
displayInfo.append("<a class=\"previous_page\" rel=\"prev\" href='" + path +"&page="+ (currentPage - 1) + "'>Prev</a>");
}
if (currentPage < totalPage)
{
displayInfo.append("<a class=\"next_page\" rel=\"next\" href='" + path +"&page="+ (currentPage + 1) + "'>Next</a>");
}
}
return displayInfo.toString();
}
}
控制层
PageHelper p = new PageHelper();
String dev_ = appWordRank.getDev() == null ? "" : appWordRank.getDev();
String country_ = appWordRank.getCountry()==null?"":appWordRank.getCountry();
String path = "rank?appid=" + appid + "&dev=" + dev_ + "&country="+country_;
p.setTotalPage(totalPages);
p.setPageSize(pageSize);
p.setPath(path);
p.setCurrentPage(page);
model.addAttribute("pager", p.getPageHTML());
页面
<div class="page">
<div class="pagination" th:utext="${pager}"></div>
</div>
本文来自博客园,作者:小珍珠在河里敲代码,转载请注明原文链接:https://www.cnblogs.com/Jansens520/p/6389097.html