全面超越 Velocity 的全新一代 Java 模板引擎 jetbrick-template 1.2.3 正式版发布。
jetbrick-template 是一个新一代 Java 模板引擎,具有高性能和高扩展性。 适合于动态 HTML 页面输出或者代码生成,可替代 JSP 页面或者 Velocity 等模板。 指令和 Velocity 相似,表达式和 Java 保持一致,易学易用。
- 支持类似与 Velocity 的多种指令
- 支持静态编译
- 支持编译缓存
- 支持热加载
- 支持类型推导
- 支持泛型
- 支持可变参数方法调用
- 支持方法重载
- 支持类似于 Groovy 的方法扩展
- 支持函数扩展
- 支持自定义标签 #tag
- 支持宏定义 #macro
- 支持布局 Layout
项目地址:http://subchen.github.io/jetbrick-template/index.html
在线中文文档:http://subchen.github.io/jetbrick-template/
范例参考:https://github.com/subchen/jetbrick-template-webmvc-samples/
1. 新增 JDT (Eclipse Java Compiler)
# 使用 JDK Compiler (默认值)
compile.tool = jetbrick.template.compiler.JdkCompiler
# 使用 Eclipse Java Compiler
compile.tool = jetbrick.template.compiler.JdtCompiler
2. 新增自定义全局变量支持
// 配置
global.variables = sample.GlobalVariables
// 实现
public class GlobalVariables implements JetGlobalVariables {
@Override
public Object get(JetContext context, String name) {
if ("copyright".equals(name)) {
return "copyright@2000-2010";
} else if ("today".equals(name)) {
return new Date();
} else if ("contextPath".equals(name)) {
HttpServletRequest request = (HttpServletRequest) context.get(JetWebConfig.REQUEST);
return request.getContextPath();
}
return null;
}
}
// 使用
${copyright}
${today.format("yyyy-MM-dd")}
${contextPath}
3. 完善支持下面的服务器
- Tomcat
- Jetty
- Resin
- JBoss/Wildfly
- Weblogic
- Glassfish