jimphei学习工作室

jimphei学习工作室

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  23 随笔 :: 0 文章 :: 1 评论 :: 0 Trackbacks
package com.yaday.test;

import java.io.StringWriter;
import java.util.Properties;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.app.VelocityEngine;
import org.junit.Test;

public class VelocityTest {
    @Test 
public void testVelocity(){
        
try {
            VelocityEngine ve 
= new VelocityEngine();
            ve.setProperty(
"resource.loader" , "class");
            ve.setProperty(
"class.resource.loader.class""org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
            ve.init();
            Template template
=null;
            template
=ve.getTemplate("velocity/first.vm");

            VelocityContext context
=new VelocityContext();
            context.put(
"name"new String("jimphei"));
            
        
            

            StringWriter sw
=new StringWriter();
            template.merge(context, sw);
            System.out.println(sw.toString());
        }
 catch (Exception e) {
            
// TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}

posted on 2009-11-10 15:15 jimphei 阅读(531) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: