分頁(yè)
##分頁(yè)控制器
##pageRedirctUrl:$pageRedirctUrl="itemLoveList.do?category=$!{category}&currPageIndex="
##pageCount 總頁(yè)數(shù)
##currPageIndex 當(dāng)前頁(yè)
#macro(pager $pageRedirctUrl,$pageCount,$currPageIndex)
#set($nextPage=$!currPageIndex+1)
#if($!currPageIndex==$!pageCount)
#set($nextPage=$!pageCount)
#end
#set($prePage=$!currPageIndex+(-1))
#if($!currPageIndex==1)
#set($prePage=1)
#end
#set($firstPage="#addUrlParam($pageRedirctUrl,'page', 1)")
#set($secondPage="#addUrlParam($pageRedirctUrl,'page', 2)")
#set($lastPage="#addUrlParam($pageRedirctUrl, 'page',$pageCount)")
#set($prePage="#addUrlParam($pageRedirctUrl,'page', $prePage)")
#set($nextPage="#addUrlParam($pageRedirctUrl,'page',$nextPage)")
#set($endPage="#addUrlParam($pageRedirctUrl,'page', $pageCount)")
#if($pageCount>1)
<div class="dataTables_paginate paging_bootstrap pagination">
<ul>
#if($currPageIndex != 1)
<li class="prev "><a href="$prePage">上一頁(yè)</a></li>
#else
<li class="prev disabled"><a href="#">上一頁(yè)</a></li>
#end
#if($pageCount >=9)
#if($!{currPageIndex} !=1)
<li><a href="$!{firstPage}">1</a></li>
#else
<li class="active"><a href="#">1</a></li>
#end
#if($!{currPageIndex} !=2)
<li><a href="$!{secondPage}">2</a></li>
#else
<li class="active"><a href="#">2</a></li>
#end
#end
#if(${currPageIndex} > $!{pageCount})
#set(${currPageIndex} = $!{pageCount})
#end
#if($!{currPageIndex}>0)
#if($!{pageCount} <=8)
#set($pageStart =1)
#set($pageEnd = $!{pageCount} - 1)
#else
#if($!{pageCount} - $!{currPageIndex}<=3)
<li><a href="#">...</a></li>
#set($pageStart =$currPageIndex - 2)
#set($pageEnd = $!{pageCount} - 1)
#else
#if($!{currPageIndex}>=10)
<li><a href="#">...</a></li>
#set($pageStart =$currPageIndex - 3)
#set($pageEnd =$currPageIndex + 2)
#if(${pageEnd} > $!{pageCount})
#set(${pageEnd} = $!{pageCount})
#end
#set($afterApo = 1)
#else
#set($pageStart =3)
#set($pageEnd =$!{currPageIndex}+2)
#set($afterApo = 1)
#end
#end
#end
#foreach($id in [${pageStart}..${pageEnd}])
#if($!id==$!currPageIndex)
<li class="active"><a href="#">$!{id}</a></li>
#else
<li><a href="#addUrlParam($pageRedirctUrl,'page',$!{id})">$!{id}</a></li>
#end
#end
#end
#if($!{pageCount}>1)
#if($afterApo)
<li><a href="#">...</a></li>
#end
#if($!pageCount!=$!currPageIndex)
<li><a href="$!{endPage}">$!{pageCount}</a></li>
<li class="next"><a href="$!{nextPage}">下一頁(yè) → </a></li>
#else
<li><a href="#">$!{currPageIndex}</a></li>
#end
#end
</ul>
</div>
#end
#end
計(jì)算頁(yè)碼
##計(jì)算頁(yè)碼 $totalNum總數(shù) $pageNum每頁(yè)的頁(yè)數(shù)
#macro(calcuPage $totalNum,$pageNum)
#if($!{totalNum} && $!{pageNum})
#if($totalNum == 0)
1
#else
#set($result = ($totalNum - 1) / $pageNum + 1)
$result
#end
#else
1
#end
#end
拼湊url參數(shù)的宏
#macro(addUrlParam $url, $paramName, $paramValue)
#if($!{url} && $!{paramName} && $!{paramValue})
#set($separator = "&")
#if($!{url.indexOf("?")} == -1)
#set($separator = "?")
#end
$url$separator$paramName=$!{paramValue}
#end
#end
分解url參數(shù)的宏
#macro(removeUrlParam $url, $paramName, $paramValue)
#if($!{url} && $!{paramName} && $!{paramValue})
#set($beReplace=$!{paramName}+"="+$!{paramValue})
#set($url=$!{url.replace($!{beReplace},"")})
#set($url = $url.replace("&&", "&"))
#set($url = $!{url.replace("?&", "?")})
#if($url.endsWith("?"))
#set($url = $!{url.replace("?", "")})
#end
#set($url = $!{url.replaceAll(" ","")})
#set($url = $!{url.replaceAl(" ","")})
#if($!{url.endsWith("&")})
#set($url = $!{url.substring(0,$!{url.lastIndexOf("&")})})
#end
$url
#end
#end
在URL中添加查詢(xún)參數(shù)
#macro(addQueryParam $url,$paramValue)
#if($!{url})
#if($!{url.indexOf("?")}<0)
$!{url}?q=$paramValue
#else
#set($qIndex=$!{url.indexOf("q=")})
#if($!{qIndex}<0)
$!{url}&q=$!{paramValue}
#else
#set($beforeStr = $!{url.substring(0,$!{qIndex})})
#set($afterStr = $!{url.substring($!{qIndex}, $!{url.length()})})
#set($index=$!{afterStr.indexOf("&")})
#if ($!{index}<0)
${url},$!{paramValue}
#else
#set($beforeStr1=$!{afterStr.substring(0,$!{index})})
#set($afterStr1 = $!{afterStr.substring($!{index}, $!{afterStr.length()})})
$!{beforeStr}$!{beforeStr1},$!{paramValue}$!{afterStr1}
#end
#end
#end
#end
#end
刪除URL中的查詢(xún)參數(shù)
#macro(removeQueryParam $url,$paramValue)
#if($!{url})
#if($!{url.contains(",$!{paramValue}")})
$!{url.replace(",$!{paramValue}", "")}
#elseif($!{url.contains("$!{paramValue},")})
$!{url.replace("$!{paramValue},", "")}
#elseif($!{url.contains("q=$!{paramValue}")})
#set($str=$!{url.replace("q=$!{paramValue}","")})
#if($!{str.contains("?&")})
#set($str=$!{str.replace("?&","?")})
#elseif($!{str.contains("&&")})
#set($str=$!{str.replace("&&","&")})
#elseif($!{str.endsWith("?")})
#set($str = $!{str.substring(0,$!{str.lastIndexOf("?")})})
#elseif($!{str.endsWith("&")})
#set($str = $!{str.substring(0,$!{str.lastIndexOf("&")})})
#end
$!{str}
#end
#end
#end
初始化URL
#macro(initUrl $url)
#if($!{url})
#if($!{url.endsWith("?")})
#set($url = $!{url.replace("?", "")})
#end
#set($url = $!{url.replace("?&", "?")})
$url
#end
#end
將數(shù)字格式化
#macro(discountFormat $discount)
$number.format('#0.0',$discount)
#end
double類(lèi)型小數(shù)點(diǎn)控制到后兩位
#macro(numFormat $num)
$number.format('#0.00',$num)
#end
文本長(zhǎng)度控制,由于是字符串
##文本長(zhǎng)度控制,由于是字符串
##str 需要長(zhǎng)度控制的字符串
##maxLength 截取的最大長(zhǎng)度
##subfix 后綴
#macro(previewText $str,$maxLength,$subfix)
#if(!$!{str}||!$!{maxLength}||!$!{subfix})
##是空則不執(zhí)行
#else
#if(${str.length()}>${maxLength})
$!{str.substring(0,${maxLength})}$!{subfix}
#else
$!{str}
#end
#end
#end
格式化時(shí)間戳
#macro(formatTime $timestamp)
$timestamp.toString().substring(0,19)
#end
將地區(qū)代碼轉(zhuǎn)換成對(duì)應(yīng)的中文
##將地區(qū)代碼轉(zhuǎn)換成對(duì)應(yīng)的中文
#macro(transAreaCode $areaCode)
#if($!{areaCode})
#if($areaCode == "340000")
安徽
#elseif($areaCode == "110000")
北京
#elseif($areaCode == "350000")
福建
#elseif($areaCode == "620000")
甘肅
#elseif($areaCode == "440000")
廣東
#elseif($areaCode == "450000")
廣西
#elseif($areaCode == "520000")
貴州
#elseif($areaCode == "460000")
海南
#elseif($areaCode == "130000")
河北
#elseif($areaCode == "410000")
河南
#elseif($areaCode == "230000")
黑龍江
#elseif($areaCode == "420000")
湖北
#elseif($areaCode == "430000")
湖南
#elseif($areaCode == "220000")
吉林
#elseif($areaCode == "320000")
江蘇
#elseif($areaCode == "360000")
江西
#elseif($areaCode == "210000")
遼寧
#elseif($areaCode == "150000")
內(nèi)蒙古
#elseif($areaCode == "640000")
寧夏
#elseif($areaCode == "630000")
青海
#elseif($areaCode == "370000")
山東
#elseif($areaCode == "140000")
山西
#elseif($areaCode == "610000")
陜西
#elseif($areaCode == "310000")
上海
#elseif($areaCode == "510000")
四川
#elseif($areaCode == "120000")
天津
#elseif($areaCode == "540000")
西藏
#elseif($areaCode == "650000")
新疆
#elseif($areaCode == "530000")
云南
#elseif($areaCode == "330000")
浙江
#elseif($areaCode == "500000")
重慶
#end
#end
#end
計(jì)算分潤(rùn)
## $totalAmount
## $userRate
## $superiorRate
#macro(calcuBenefit $totalAmount,$userRate,$superiorRate)
#set($allBenefit = $math.mul($!{totalAmount},$!{userRate}))
#set($superiorBenefit = $math.mul($!{totalAmount},$!{superiorRate}))
$number.format("#0.00",$math.sub($allBenefit,$superiorBenefit))
#end