public class VelocityUtil extends Object
| 构造器和说明 |
|---|
VelocityUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
getContent(String templateDir,
String templateFileName,
org.apache.velocity.VelocityContext context,
String charset)
获得指定模板填充后的内容
|
static String |
getContent(String templateFileName,
org.apache.velocity.VelocityContext context)
获得指定模板填充后的内容,使用默认引擎
|
static String |
getContent(org.apache.velocity.app.VelocityEngine ve,
String templateFileName,
org.apache.velocity.VelocityContext context)
获得指定模板填充后的内容
|
static void |
init(String templateDir,
String charset)
初始化Velocity全局属性
|
static String |
merge(String templateContent,
org.apache.velocity.VelocityContext context)
融合模板和内容
|
static org.apache.velocity.app.VelocityEngine |
newEngine(String templateDir,
String charset)
新建Velocity模板引擎
|
static org.apache.velocity.VelocityContext |
parseRequest(javax.servlet.http.HttpServletRequest request)
将Request中的数据转换为模板引擎
|
static void |
toFile(String templateFileName,
org.apache.velocity.VelocityContext context,
String destPath)
生成文件,使用默认引擎
|
static void |
toFile(org.apache.velocity.Template template,
org.apache.velocity.VelocityContext context,
String destPath)
生成文件
|
static void |
toFile(org.apache.velocity.app.VelocityEngine ve,
String templateFileName,
org.apache.velocity.VelocityContext context,
String destPath)
生成文件
|
static void |
toWriter(String templateFileName,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
生成内容写到响应内容中
模板的变量来自于Request的Attribute对象 |
static void |
toWriter(String templateFileName,
org.apache.velocity.VelocityContext context,
Writer writer)
生成内容写入流
会自动关闭Writer |
static void |
toWriter(org.apache.velocity.app.VelocityEngine ve,
String templateFileName,
org.apache.velocity.VelocityContext context,
Writer writer)
生成内容写入流
会自动关闭Writer |
public static void init(String templateDir, String charset)
templateDir - 模板所在目录,绝对路径public static org.apache.velocity.app.VelocityEngine newEngine(String templateDir, String charset)
templateDir - 模板所在目录,绝对路径public static String getContent(String templateDir, String templateFileName, org.apache.velocity.VelocityContext context, String charset)
templateDir - 模板所在目录,绝对路径templateFileName - 模板名称context - 上下文(变量值的容器)charset - 字符集public static String getContent(org.apache.velocity.app.VelocityEngine ve, String templateFileName, org.apache.velocity.VelocityContext context)
ve - 模板引擎templateFileName - 模板名称context - 上下文(变量值的容器)public static String getContent(String templateFileName, org.apache.velocity.VelocityContext context)
templateFileName - 模板文件context - 上下文(变量值的容器)public static void toFile(org.apache.velocity.app.VelocityEngine ve,
String templateFileName,
org.apache.velocity.VelocityContext context,
String destPath)
ve - 模板引擎templateFileName - 模板文件名context - 上下文destPath - 目标路径(绝对)public static void toFile(String templateFileName, org.apache.velocity.VelocityContext context, String destPath)
templateFileName - 模板文件名context - 模板上下文destPath - 目标路径(绝对)public static void toFile(org.apache.velocity.Template template,
org.apache.velocity.VelocityContext context,
String destPath)
template - 模板context - 模板上下文destPath - 目标路径(绝对)public static void toWriter(org.apache.velocity.app.VelocityEngine ve,
String templateFileName,
org.apache.velocity.VelocityContext context,
Writer writer)
ve - 引擎templateFileName - 模板文件名context - 上下文writer - 流public static void toWriter(String templateFileName, org.apache.velocity.VelocityContext context, Writer writer)
templateFileName - 模板文件名context - 上下文writer - 流public static String merge(String templateContent, org.apache.velocity.VelocityContext context)
templateContent - 模板的内容字符串context - 上下文public static void toWriter(String templateFileName, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
templateFileName - 模板文件request - 请求对象,用于获取模板中的变量值response - 响应对象public static org.apache.velocity.VelocityContext parseRequest(javax.servlet.http.HttpServletRequest request)
request - 请求对象Copyright © 2015. All rights reserved.