Freemarker后台分页,JFinal enjoy后台分页

2个后台分页,仅供参考。

 

FreeMarker后台分页

page方法名,url,第2个page  是后台分页对象,里面有 pageNo,totalPage等参数。

ageVo {
	private static Logger log = Logger.getLogger(PageVo.class);

	public static final Integer DEFAULT_PAGE_SIZE = 20;
	public static final Integer MAX_PAGE_SIZE = DEFAULT_PAGE_SIZE * 2;

	// 前端传入
	/** 第几页 */
	protected Integer pageNo = 1;
	/** 每页显示条数 */
	protected Integer pageSize = 10;

	// 计算得到
	/** 总记录数 */
	protected Integer totalCount = 0;
	/** 总共有多少页 */
	protected Integer totalPage = 0;

	/** 第1条记录的编号 */
	protected Integer startNo = 1;
	/** 最后1条记录的编号 */
	protected Integer endNo = 1;

	/** 表格中的数据 */
	protected List<?> rows;
}
<#macro page url page maskSize=5>
	<#assign url2="${url?url?replace('%2F','/')?replace('%3D','=')?replace('%3F','?')?replace('%26','&')}">
    <#assign number = page.pageNo>
    <#assign pages = page.totalPage>
      <#if pages == 0>
        <#return>
    </#if>
    
    <#if (maskSize % 2) == 0>
        <#assign maskSize = maskSize + 1>
    </#if>
    <#assign PadNum = (maskSize / 2)?int>   
    
	<#assign startNumber = 1>
	<#assign endNumber = 1>
    <ul class="pagination">
    <#if pages <= maskSize >
		<#assign startNumber = 1>
		<#assign endNumber = pages>
	<#elseif (number - PadNum <= 0)>
		<#assign startNumber = 1>
		<#assign endNumber = maskSize>
	<#elseif (number + PadNum > pages)>
		<#assign startNumber = pages - maskSize + 1>
		<#assign endNumber = pages>
	<#else>
		<#assign startNumber = number - PadNum>
		<#assign endNumber = number + PadNum>
    </#if>
     
    <#if (number == 1)>
       <li><a href="javascript:void(0);">首页</a></li>
	   <li><a href="javascript:void(0);">上一页</a></li>
    <#else>
           <li><a href="${buildPageUrl(url2,1,page)}">首页</a></li> 
           <li><a href="${buildPageUrl(url2,page.pageNo-1,page)}">上一页</a></li>     
    </#if>
  
    <#list startNumber..endNumber as pageNo>
    	<#if (number == pageNo)>
			<li class="active"><a href="javascript:;">${pageNo}</a></li>
		<#else>
	       <li> <a href="${buildPageUrl(url2,pageNo,page)}">${pageNo?int?c}</a></li>        
        </#if> 
    </#list>
    
    <#if (number == pages)>
		  <li><a href="javascript:void(0);" class="disabled">下一页</a></li>
		  <li><a href="javascript:void(0);" class="disabled">尾页</a></li>
    <#else>
        <li><a href="${buildPageUrl(url2,page.pageNo+1,page)}" >下一页</a></li>   
         <li><a href="${buildPageUrl(url2,page.pages,page)}">尾页</a></li>   
    </#if>
	<li><span>共${page.totalPage}页</span></li>
	</ul>
</#macro>

<#function buildPageUrl url pageNo data>
      <#if url?contains('?') >
              <#assign pageUrl = "${url}&pageNo=${pageNo}&pageSize=${data.pageSize}">
           <#else>
             <#assign pageUrl = "${url}?pageNo=${pageNo}&pageSize=${data.pageSize}">
      </#if>
    
    <#if data.orderBy != null>
      <#assign pageUrl ="${pageUrl}&orderBy=${data.orderBy}"/>
    </#if>
    <#if data.order != null>
      <#assign pageUrl ="${pageUrl}&order=${data.order}"/>
    </#if>
     <#if data.startDate != null>
      <#assign pageUrl ="${pageUrl}&startDate=${data.startDate}"/>
    </#if>
     <#if data.endDate != null>
      <#assign pageUrl ="${pageUrl}&endDate=${data.endDate}"/>
    </#if>
    <#return pageUrl/>
</#function>

 

JFinal enjoy后台分页

 

<!-- jfinal enjoy模版,分页函数,只负责展示,不存在计算 -->
<!-- layui 分页样式 -->
#define fnPage(url,page)
     #if(page.pages<=0)
        return
     #end

      <div id="micronews-details-test" style="text-align: center;">
		<div class="layui-box layui-laypage layui-laypage-default" id="layui-laypage-1">
			    #if(page.current == 1)>
			      <a href="javascript:void(0);"  class="layui-laypage-prev layui-disabled">首页</a>
				  <a href="javascript:void(0);"  class="layui-laypage-prev layui-disabled">上一页</a>
			    #else
			          <a href="#@buildPageUrl(url,1,page)">首页</a> 
			          <a href="#@buildPageUrl(url,page.current-1,page.size)">上一页</a>     
			   #end
			  
			  #for(pageNo = page.startNumber; pageNo <= page.endNumber; pageNo++)
		   		  #if(page.current== pageNo)
		   		      	<span class="layui-laypage-curr"><em class="layui-laypage-em"></em><em>#(pageNo)</em></span>
		   		  #else
		   		     <a href="#@buildPageUrl(url,pageNo,page.size)">#(pageNo)</a>        
		   		  #end
		   	 #end
		
			    #if (page.current == page.pages)
					 <a href="javascript:void(0);" class="disabled"  class="layui-laypage-prev layui-disabled">下一页</a>
					 <a href="javascript:void(0);" class="disabled"  class="layui-laypage-prev layui-disabled">尾页</a>
			    #else
			       <a href="#@buildPageUrl(url,page.current+1,page.size)">下一页</a>   
			        <a href="#@buildPageUrl(url,page.pages,page.size)">尾页</a>   
			    #end
				<span>共#(page.pages)页</span>
			</div>
		
		</div>
		#end

#define fnPageDetail(url,current,size)
   #(url),#(pageData)
#end


#define buildPageUrl(url,current,size)
      #if(url.contains('?'))
           #(url)&current=#(current)&size=#(size)
      #else
           #(url)?current=#(current)&size=#(size)
      #end
#end

 

 

 



import java.io.Serializable;
import java.util.List;

import com.google.common.collect.Lists;

import lombok.Data;

@Data
public class Page<T> implements Serializable {

	private static final long serialVersionUID = 4534606231897214604L;

	/**
	 * 总数
	 */
	private int total = 0;
	/**
	 * 每页显示条数,默认 10
	 */
	private int size = 10;
	/**
	 * 当前页
	 */
	private int current = 1;
	private int pages;
	/**
	 * 查询数据列表
	 */
	private List<T> rows = Lists.newArrayList();

	public static <T> Page<T> one() {
		return new Page<T>();
	}

	public static <T, S> Page<T> build(Page<S> sourcePage, List<T> rows) {
		Page<T> page = Page.one();
		page.setCurrent(sourcePage.getCurrent());
		page.setPages(sourcePage.getPages());
		page.setSize(sourcePage.getSize());
		page.setRows(rows);
		return page;

	}

	// 模版渲染-后台分页用
	private int maskSize = 5;
	private int padNum = maskSize / 2;
	private int startNumber = 1;
	private int endNumber = 1;

	//如果需要后端分页,就需要手动调用
	public void init() {
		if (pages <= maskSize) {
			startNumber = 1;
			endNumber = pages;
		}
		else if (current - padNum <= 0) {
			startNumber = 1;
			endNumber = maskSize;
		} else if (current + padNum > pages) {
			startNumber = pages - maskSize + 1;
			endNumber = pages;
		} else {
			startNumber = current - padNum;
			endNumber = current + padNum;
		}
	}

}

 

©️2020 CSDN 皮肤主题: 猿与汪的秘密 设计师: 上身试试 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值