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 閱讀(554) 評論(0)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 肥西县| 渝北区| 南宁市| 墨竹工卡县| 曲阳县| 横山县| 万源市| 清水河县| 开封县| 龙州县| 通化市| 巴马| 固镇县| 项城市| 南岸区| 枝江市| 乐陵市| 衡南县| 夏邑县| 揭阳市| 华容县| 霍山县| 通化市| 洛隆县| 双流县| 卢湾区| 无锡市| 山阳县| 沂源县| 城步| 盐源县| 锡林郭勒盟| 洮南市| 丹棱县| 沈阳市| 嘉荫县| 汉寿县| 会理县| 丹凤县| 延安市| 英吉沙县|