FreeMarker应用

<#import "../common/main.ftl" as page> <#import  "../common/pager.ftl" as my> <#include "../common/constant.ftl" /> <@page.main type="" title=""> //给公共模板main.ftl中type,title属性赋值

<style type="text/css">

</style> <script>

</script>

<form action="${(domainPath)!}/jfEvent/findMarketList.mxd" method="post">     <input type="hidden" name="channelId" value="${(channelId)!}">     <input type="hidden" name="categoryId" value="${(categoryId)!}">     <input type="hidden" name="lowScore" value="${(lowScore)!}">     <input type="hidden" name="highScore" value="${(highScore)!}">     <#if lists ??>       <#assign index=0 />       <#list lists as list>         <#assign index=index+1/>         <a href="${(domainPath)!}/jfEvent/queryItemInfo.mxd?id=${(list.eventId)!‘‘}" target="_blank"><img src="${(page.domainImagePath)}/${(list.image)!‘‘}"></a><         ${(list.name)!‘‘}         ${(list.score)!}         ${(list.price)!‘‘}      </#list> <@my.pager listpage = pagination/> //给分页模板pager.ftl中listpage属性赋值 </form>

</@page.main>

main.ftl: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head>     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />     <title>${(title)!}</title>     <link rel="stylesheet" type="text/css" href="${(domainPath)!}/resources/css/base.css" />     <link rel="stylesheet" type="text/css" href="${(domainPath)!}/resources/css/homepage.css" />     <link rel="stylesheet" type="text/css" href="${(domainPath)!}/resources/css/public.css" />     <link rel="stylesheet" type="text/css" href="${(domainPath)!}/resources/css/auction.css" />     <#--<script type="text/javascript" src="${(domainPath)!}/resources/js/jquery.js"></script>-->     <script type="text/javascript" src="${(domainPath)!}/resources/js/jquery-1.8.3.js"></script>     <script type="text/javascript" src="${(domainPath)!}/resources/js/jquery.validate.js"></script>     <script type="text/javascript" src="${(domainPath)!}/resources/js/jquery.form.js"></script>     <script type="text/javascript" src="${(domainPath)!}/resources/js/Ajax.js"></script>     <link rel="stylesheet" type="text/css" href="http://www.minxindai.com/static/css/jbox.css" />     <script type="text/javascript" src="http://www.minxindai.com/static/js/jquery.jBox-2.3.min.js"></script>     <script type="text/javascript" src="http://www.minxindai.com/static/js/jquery.jBox-zh-CN.js"></script>     <script type="text/javascript" src="${(domainPath)!}/resources/js/focus.js"></script>     <script type="text/javascript" src="${(domainPath)!}/resources/js/global.js"></script>     <script type="text/javascript" src="${((domainPath)!)!}/resources/js/PCASClass.js" charset="utf-8"></script>     <script type="text/javascript" src="${(domainPath)!}/resources/DatePicker/WdatePicker.js"></script> </head> <body>     <#include "head.ftl">     <#if type=="0">         <div class="content-bg-white pt10">             <#nested>         </div>     <#elseif type=="1">         <div class="content-bg-white pt10">             <div class="wrap">                  <@channel onCur=onCur navigater=navigater></@channel>                  <#nested>             </div>         </div>     </#if>     <#include "foot.ftl"> </body> </html> </#macro> <#macro channel onCur="" navigater=""> <div class="navgation-box clear">     <a href="${(domainPath)!}/find.mxd">         <dl class="s1 <#if onCur=="1">cur</#if>" >             <dt></dt>             <dd></dd>         </dl>     </a> </div> <!--navgation-box--end--> <#if navigater="1"> <div class="bread-nav-wp">     <a href="/jfEvent/getHomePage.mxd">首页</a>     <#if navigater ??>         <span>&gt;</span>         <a href="${(navigater.url)!}">${(navigater.name)!}</a>     </#if> </div> </#if> </#macro> <script> function find(){     window.location.href = "${(domainPath)!}/find.mxd"; } </script>

head.ftl:                 <a href="${(domainHomePath)!}/?m=user&c=login" class="orange-link fl">登录</a>                 <span class="space colccc fl">|</span>                 <a href="${(domainHomePath)!}/?m=user&c=reg"class="orange-link fl">注册</a>                 <#else>                 <span class="orange-link fl">${username},您好</span>

foot.ftl:             <div class="foot_saoma fl mr30">                 <p class="fl f13">微信二维码<br>                     <img src=""></p>             </div>

<div class="fl pl30">                 <div class="foot_contact_bottom pt68">                     <p class="foot_contact_bottom_telfont col515151 f16">客服热线:</p>                     <a class="coldc3a24 f20" href="#"></a>                 </div>             </div> <p>版权所有&nbsp;&nbsp;保留所有权利&nbsp;&nbsp;京ICP备13005404号-2</p>

pager.ftl: <#macro pager listpage =""> <input name="pageNo" id="pageNo" type="hidden" value="1"> <input name="pageSize" id="pageSize" type="hidden" value="${(pageSize)!9}"> <div class="clear page_zf">     <div class="page_fen">     <#if listpage??>             <#--[总数:${(listpage.totalCount)!}条]&nbsp;&nbsp;-->             <#--<a href="javascript:gotopage(1);">首页&nbsp;&nbsp;</a>-->             <#--${(listpage.totalPage)!}-->             <#if listpage.totalPage < 10>                 <#if listpage.pageNo<=1>                     <a href="javascript:void(0);" class="uppage_btn btn_stop arrow-left"><i></i>上一页</a>                 <#else>                     <a href="javascript:gotopage(${(listpage.pageNo-1)});" class="uppage_btn arrow-left"><i></i>上一页</a>                 </#if>                 <ul class="page_fen_ul">                 <#list 1..listpage.totalPage as n>                      <li class="page_fen_li"><a class="page_fen_a <#if listpage.pageNo==n > page_num_spe</#if>" href="javascript:gotopage(${(n)});">${n}</a></li>                 </#list>                 </ul>                 <#if (listpage.pageNo>=listpage.totalPage) >                     <a href="javascript:void(0);" class="downpage_btn btn_stop arrow-right">下一页<i></i></a>                 <#else >                     <a href="javascript:gotopage(${(listpage.pageNo+1)});" class="downpage_btn arrow-right">下一页<i></i></a>                 </#if>             <#else>                 <#if listpage.pageNo<=1>                     <a href="javascript:void(0);" class="uppage_btn btn_stop arrow-left"><i></i>上一页</a>                 <#else>                     <a href="javascript:gotopage(${(listpage.pageNo-1)});" class="uppage_btn arrow-left"><i></i>上一页</a>                 </#if>

<#if listpage.pageNo <=4 >                     <ul class="page_fen_ul">                         <#list 1..5 as n>                             <li class="page_fen_li"><a class="page_fen_a <#if listpage.pageNo==n > page_num_spe</#if>" href="javascript:gotopage(${(n)});">${n}</a></li>                         </#list>                             <li class="page_fen_li">...</li>                             <li class="page_fen_li"><a class="page_fen_a" href="javascript:gotopage(${listpage.totalPage});">末页</a></li>                     </ul>                 <#elseif (listpage.pageNo > 4) && (listpage.pageNo <= listpage.totalPage-4) >                     <ul class="page_fen_ul">                         <li class="page_fen_li"><a class="page_fen_a" href="javascript:gotopage(1);">首页</a></li>                         <li class="page_fen_li">...</li>

<#list listpage.pageNo-2..listpage.pageNo+2 as n>                             <li class="page_fen_li"><a class="page_fen_a <#if listpage.pageNo==n > page_num_spe</#if>" href="javascript:gotopage(${(n)});">${n}</a></li>                         </#list>

<li class="page_fen_li">...</li>                         <li class="page_fen_li"><a class="page_fen_a" href="javascript:gotopage(${listpage.totalPage});">末页</a></li>                     </ul>                 <#elseif (listpage.pageNo > (listpage.totalPage-5)) >                     <ul class="page_fen_ul">                         <li class="page_fen_li"><a class="page_fen_a" href="javascript:gotopage(1);">首页</a></li>                         <li class="page_fen_li">...</li>                         <#list listpage.totalPage-5..listpage.totalPage as n>                             <li class="page_fen_li"><a class="page_fen_a <#if listpage.pageNo==n > page_num_spe</#if>" href="javascript:gotopage(${(n)});">${n}</a></li>                         </#list>

</ul>                 </#if>                 <#if (listpage.pageNo>=listpage.totalPage) >                     <a href="javascript:void(0);" class="downpage_btn btn_stop arrow-right">下一页<i></i></a>                 <#else >                     <a href="javascript:gotopage(${(listpage.pageNo+1)});" class="downpage_btn arrow-right">下一页<i></i></a>                 </#if>             </#if>     </#if>     </div> </div> <script>     function gotopage(pageNo){         if(pageNo>=1&&pageNo<=${(listpage.totalPage)!}){             document.getElementById("pageNo").value = pageNo;             document.forms[0].submit();         }     } </script> </#macro>

时间: 2024-10-28 16:31:27

FreeMarker应用的相关文章

Maven+SpringMVC+Freemarker入门Demo

1 参考http://blog.csdn.net/haishu_zheng/article/details/51490299,用第二种方法创建一个名为mavenspringmvcfreemarker的Maven工程. 2 文件目录结构如下图所示 3 在pom.xml中添加springmvc和freemarker的依赖包,添加完之后的完整内容为 [html] view plain copy <project xmlns="http://maven.apache.org/POM/4.0.0&q

Freemarker商品详情页静态化服务调用处理

--------------------------------------------------------------------------------------------- [版权申明:本文系作者原创,转载请注明出处] 文章出处:http://blog.csdn.net/sdksdk0/article/details/53151462 作者:朱培      ID:sdksdk0 ----------------------------------------------------

Freemarker 之 Java静态化 实例一

Freemarker是一种强大的web端模板技术,在当前Web开发中,SEO和客户端浏览速度尤为重要,其中将网页静态化是一个很好的解决方案.下面介绍Java中web开发结合Freemarker来实现静态化. 主要分为三步 1 准备好模板文件,如Test.ftl <html> <head> <title>${title}</title> <style type="text/css" link="${rccontextPath

FreeMarker中的日期时间处理

1. FreeMarker中的日期时间格式设置 FreeMarker中可以分别对date.time.datetime三种类型的日期时间设置格式,例如: config.setDateTimeFormat("yyyy-MM-dd HH:mm:ss"); config.setDateFormat("yyyy-MM-dd"); config.setTimeFormat("HH:mm:ss"); 当我们对一个页面变量使用 ?date ?time ?date

Spring mvc 中使用ftl引用共通文件出错 FreeMarker template error: Error reading included file &quot;/WEB-INF/ftl/common/errormessage.ftl&quot;

初次接触spring mvc,想做一个小的练习项目,结果在ftl文件中引用其它的共通ftl文件时出错. 目录结构如图所示,想在login.ftl中引用common下的errormessage.ftl <#include '/WEB-INF/ftl/common/errormessage.ftl' /> 结果画面报错: FreeMarker template error: Error reading included file "/WEB-INF/ftl/common/errormes

freemarker整理

1.FreeMarker模板的内建变量有如下几个: 1,stack:代表ValueStack本身,可通过如下方式来访问其中的变量"${stack.findString('ognl?expr')}" 2,action:代表刚刚执行过的Action实例 3,response:代表HpptServletResponse实例 4,res:代表HpptServletResponse实例 5,request:代表HpptServletRequest实例 6,req:代表HpptServletReq

Spring整合freemarker发送邮件

一. 背景知识 在上一篇博文: 使用JavaMail发送邮件和接受邮件, 我们学习了原生的JavaApi发送邮件, 我们会发现代码比較多, 特别是当邮件内容非常丰富的时候, 我们须要在Java中拼装Html, 是不是认为非常麻烦. 以下我们使用一种比較简单的方法: spring + javaMail + freemarker, 使用freemarker模板引擎后, 我们就不用再在Java中拼装html. 二. 环境准备 废话不多说了, 以下我们准备下开发环境: 1. 所需Jar包: spring

Could not load the FreeMarker template named &amp;#39;select&amp;#39;

眼下项目使用struts2, 所以页面中就使用到了struts2的标签,可是今天在做新的功能的时候突然出现 "Could not load the FreeMarker template named 'select'" 这种错误. 看错误信息是找不到struts2  的select 标签,可是其它页面也都用到了select.也没有出现错误.最后发现问题出在了action中.我在action中定义了一个实体变量,起名为theme, 最后将该变量名称改掉就好了. 因为时间关系没有找到根本原

JSP FreeMarker Velocity 原理

JSP原理 JSP的运行原理:JSP 本质上是一个Servlet. 每个JSP 页面在第一次被访问时,JSP引擎将它翻译成一个Servlet 程序,然后再把这个 Servlet 源程序编译成Servlet 的class 类文件.然后再由WEB 容器(Servlet容器)像调用 Servlet 程序一样的方式装载和解释执行这个由JSP 页面翻译成的 Servlet 程序. FreeMarker 和 velocity 原理 在Struts2框架下,Struts2框架充当了之前的Servlet角色,只

freemarker使用

布尔型必须转为字符串输出 ${team.isClub ? string ("true", "false")} freemarker三目运算:${ (type == “SPOT”) ?string('热点词','热点搜索')} 字符串截取(索引0到索引5) ${team.picNo[0..5]} if..else 语句 <#if team.picNo?length != 18> <#else> </#if> 循环列表 <#li