随着网站一步步的发展,网站的静态化越来越重要。针对于目前市场上存在Velocity、FreeMarker、JSP三大模板引擎技术之一(现在又有Thymeleaf)的Velocity技术进行分析。
针对 velocity 模板直接生成 html 静态页面网上资料太多了,随便一搜一大把,这里不做太多的讲解。这里主要是针对velocitylayout方式的如何生成静态页面做个简单的介绍。
VelocityLayout 是通过布局的方式让功能页面简洁了很多。通过再功能页面引入指定好的layout,即可引入:
Velocity如何实现 Layout 的呢?
1, 定义好的布局,内置个变量,默认是screen_content(也可以通过配置文件修改这个变量),类似于下面的结构。


2,velocity 会在渲染指定的 vm的时候,先去渲染screen_content。


然后将变量 screen_content的 kv 放入 context。 key:screen_content, value:string 流
知道这个原理,那生成带有layout风格的 html 页面也就不难了。直接看代码即可。