11_01_25VTL模板使用要点

1、实现分页功能

##//当前导航(此处为一级导航,假设为:教育动态)
#set($currentNav = ${root.getNavigations()})
#set($nsv = $currentNav.get($root.decrease($currentNav.size())))

##//循环一级菜单下的二级菜单
#foreach($child in ${root.db.listNavigations(${nsv.topicName},${nsv.name})})
<li><a href="$child.url">$child.name</a></li>
#end

##//热点新闻
##设置为空,则返回所有新闻的热点新闻。
#set($strztrd="")  
#set($zhtrdstwo = $root.getDb().listByHotClicks(${nsv.topicName},$strztrd,11))
#foreach($ztrdt in $zhtrdstwo)
<li><img src="public/pgjyw/images/news/list4.jpg" /><a href="${ztrdt.url}">${ztrdt.title}</a></li>
#end

##//最新新闻
##为空,为所有新闻最新的信息。
#set($zxstr="")  
#set($zxddts = $root.getDb().listByNavigation(${nsv.topicName},$zxstr,11))
#foreach($zxt in $zxddts)
<li><img src="public/pgjyw/images/news/list4.jpg" /><a href="$zxt.url">$zxt.title</a></li>
#end

##//招考信息
##获取招考信息
#set($zhshxx=$shyoneChild.get(5).name)

##说明:获取二级菜单字符串。
#set($twoChild=${root.db.listNavigations(${shycurNav.topicName},${zhshxx})})
#set($ns = $root.decrease($twoChild.size()))##减一位
#set($navName='')
#foreach($i in [0..$ns])
    #set($navName = $navName +',' + ${twoChild.get(${i}).name})
#end
#set($navName = $zhshxx + $navName)

##说明:循环新闻标题。
#set($llsit = $root.getDb().listByNavigation(${shycurNav.topicName},$navName,10))

<div class="new3">        
    <div style="height:278px;">
        <div class="new-title1">
            <div class="nt">${zhshxx}</div>
            <div class="more"><a href="/zkxx">more…</a></div>
        </div>
        <ul class="new-list">
            #foreach($n in $llsit)
            <li class="nle-title">
                  <img src="public/pgjyw/images/news/list1.jpg" />
                  <a href="${n.url}">${n.title}</a>
            </li>
            #end
        </ul>
菜单:$navName
     </div>
     <div class="new-title2" ></div>
</div>


##//组装二级导航成字符串
#set($sl = ${root.db.listNavigations(${nsv.topicName},${nsv.name})})    ##说明:得到二级导航sl数组。
#set($ns = $root.decrease($sl.size()))##得到最后一个值的下标。
#set($navName='')
#foreach($i in [$ns..0])
#set($navName = $navName + ${sl.get(${i}).name} + ',')
#end
#set($navName = $navName + ${nsv.name})

##///分页功能
#**
* 显示列表内容 定义为宏
*#
#macro(lato $aList)
 <ul>
  #foreach($article in $aList)
    <li class="nle-title"><img src="public/pgjyw/images/news/list1.jpg" /><a href="${article.url}" target="">${article.title}</a></li>
    <li class="nle-time"><div>${article.createdAt}</div></li>
  #end
  </ul>
#end

#**
* 文章列表
* @param topicName 导航
* @param navigation 导航
* @param pageCount 限制条数
*#
#macro(ptb1 $url $topicName $navigation $count)
        #if(!$count)
             #set($count=2)        ##设置$count
        #end 
        #if(${root.params.limit})            
             #set($pageCount = $root.params.getInt("limit")) ##设置$pageCount
        #end   
        #if(!$pageCount)   
            $root.getParams().set("limit",${count.toString()})
            #set($pageCount=$count)
         #end         
        #set($page=${root.db.listByNavigation($topicName,$navigation)})

        #**总页数*#
        #set($totalPages=$page.totalCount/$page.limit)   
        #if($page.totalCount%$page.limit>0)
            #set($totalPages=$totalPages+1)
        #end

    #**当前页*#
    #set($currentPage=$page.start/$page.limit+1)
    #**上一页*#
    #set($lastCount= $page.start - $pageCount)
    #**下一页*#
    #set($nextCount= $page.start + $pageCount)
        #**最后一页*#
        #set($endCount= ($totalPages - 1) * $pageCount)
     
    #**当前显示开始*#
    #set($showBign = $page.start+1)
    #**当前显示结束*#
    #set($showEnd = $page.start + $pageCount)
    #if($showEnd > $page.totalCount)
        #set($showEnd = $page.totalCount)
    #end
        #**是否第一页*#
        #set($isFirstPage=$page.start==0)
        #**是否最后一页*#
        #set($isLastPage=$showEnd==$page.totalCount)
   
    <div class="new-list-e">
        #lato($page.result)
        <div style="clear:both;"></div>
    </div>
    <div class="fy">
        #if(${totalPages}>1)
            当前显示${showBign}-${showEnd}&nbsp;总${page.totalCount}条&nbsp;
                #if(!$isFirstPage)
                    <a href="${url}?start=0&limit=$pageCount">
                #end
                    <img width="13" height="14" src="public/pgjyw/images/news/fy_first.jpg" />
                #if(!$isFirstPage)
                    </a>
                #end &nbsp;
                #if(!$isFirstPage)
                    <a href="${url}?start=${lastCount}&limit=$pageCount">
                #end
                    <img width="11" height="14" src="public/pgjyw/images/news/fy_before.jpg" />
                #if(!$isFirstPage)
                                        </a>
                #end &nbsp;
            第<input type="text" class="now-page" name="page" size="8" value="${currentPage}" />页&nbsp;
            共&nbsp;<label>${totalPages}</label>&nbsp;页&nbsp;
                #if(!$isLastPage)
                    <a href="${url}?start=${nextCount}&limit=$pageCount">
                #end
                    <img width="11" height="14" src="public/pgjyw/images/news/fy_next.jpg" />
                #if(!$isLastPage)
                    </a>
                #end &nbsp;
                #if(!$isLastPage)
                    <a href="${url}?start=${endCount}&limit=$pageCount">
                #end
                    <img width="13" height="14" src="public/pgjyw/images/news/fy_last.jpg" />
                #if(!$isLastPage)
                    </a>
                #end
        #end
    </div>
        #**-------当前页:${currentPage},总页数:${totalPages},开始页:${page.start},每页条数:${pageCount}   *#
#end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值