jimphei學(xué)習(xí)工作室

          jimphei學(xué)習(xí)工作室

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            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 閱讀(548) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 惠来县| 离岛区| 平陆县| 班玛县| 分宜县| 宜春市| 内江市| 光山县| 桂东县| 吕梁市| 奉贤区| 寿光市| 白山市| 光山县| 彰武县| 修文县| 江源县| 江川县| 宁蒗| 齐河县| 昭通市| 满城县| 奉贤区| 安陆市| 平乐县| 大同市| 涞水县| 当涂县| 江安县| 西昌市| 措勤县| 赤水市| 米易县| 双牌县| 临湘市| 获嘉县| 宜兴市| 伊吾县| 黄龙县| 资溪县| 专栏|