SiteMesh如何结合Freemarker及velocity使用
作者:cuisuqiang
这篇文章主要介绍了SiteMesh如何结合Freemarker及velocity使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
Freemarker 入门示例 https://www.jb51.net/article/197670.htm
FreeMarker 整合Struts2示例 https://www.jb51.net/article/197698.htm
SiteMesh入门示例 https://www.jb51.net/article/197668.htm
那么如何将Freemarker与SiteMesh结合起来使用,这在官方示例中已经有了相关例子。
查看官方示例中decorators.xml文件,里面有一段是关于Freemarker使用的
<decorator name="freemarker" page="freemarker.ftl"> <pattern>/freemarker.html</pattern> </decorator>
也就是说请求freemarker.html时会拦截并处理,并发freemarker.ftl作为默认页面处理
看一下freemarker.ftl的内容,因为在JSP中是使用标签来获取Head或者Body的,所以在这个页面主要是看看如何获取这些元素。
<html>
<head>
<title>Freemarker Decorator - ${title}</title>
<link href="${base}/decorators/main.css" rel="external nofollow" rel="stylesheet" type="text/css">
${head}
</head>
<body>
<div id="pageTitle">${title}</div>
<hr/>
${body}
<div id="footer">
<b>Disclaimer:</b> This site is an example site to demonstrate SiteMesh. It serves no other purpose.
</div>
</body>
</html>
可以看到,直接通过$来获取几个元素,${title}、 ${head}、${base}、${title}、${body}
velocity的结合是一样的,看看关于他的配置
<decorator name="velocity" page="velocity.vm"> <pattern>/velocity.html</pattern> </decorator>
看看velocity.vm页面内容
<html>
<head>
<title>Velocity Decorator - $title</title>
<link href="$base/decorators/main.css" rel="external nofollow" rel="stylesheet" type="text/css">
$head
</head>
<body>
<div id="pageTitle">$title</div>
<hr/>
$body
<div id="footer">
<b>Disclaimer:</b> This site is an example site to demonstrate SiteMesh. It serves no other purpose.
</div>
</body>
</html>
不多解释了。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
- 详解使用Mybatis-plus + velocity模板生成自定义的代码
- c#基于NVelocity实现代码生成
- Vue中JS动画与Velocity.js的结合使用
- 如何解决SpringBoot2.x版本对Velocity模板不支持的方案
- SpringBoot与velocity的结合的示例代码
- 聊聊JS动画库 Velocity.js的使用
- springMVC+velocity实现仿Datatables局部刷新分页方法
- 详解velocity模板使javaWeb的html+js实现模块化
- Mybatis velocity脚本的使用教程详解(推荐)
- JAVA velocity模板引擎使用实例
- html文件中jquery与velocity变量中的$冲突的解决方法
- Java 如何使用Velocity引擎生成代码
