欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

使用外部 properties 文件来配置 Velocity,propertiesvelocity,通过外部 propert

来源: javaer 分享于  点击 19030 次 点评:254

使用外部 properties 文件来配置 Velocity,propertiesvelocity,通过外部 propert


通过外部 properties 配置 Velocity,例如日志输出等等

HelloWorldExternalProperties.java

import java.io.StringWriter;import java.io.Writer;import org.apache.velocity.Template;import org.apache.velocity.VelocityContext;import org.apache.velocity.app.Velocity;public class HelloWorldExternalProperties {  public static void main(String[] args) throws Exception {    Velocity.init("./src/velocity.properties");    Template template = Velocity.getTemplate("./src/HelloWorld.vm");    VelocityContext context = new VelocityContext();    Writer writer = new StringWriter();    template.merge(context, writer);    System.out.println(writer.toString());  }}

velocity.properties

## This is a simple example of a velocity properties file.## Any property that is not listed here will have it's default# value used.  The default values are located in :#  *  src/java/org/apache/velocity/runtime/default/velocity.defaults#  *  http://jakarta.apache.org/velocity/developer-guide.html## as an example, we are changing the name of the velocity log #runtime.log = velocity_example.log

输出结果

Hello World!
相关栏目:

用户点评