<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    jimphei學習工作室

    jimphei學習工作室

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      23 隨筆 :: 0 文章 :: 1 評論 :: 0 Trackbacks

    import java.util.Map;

    import org.apache.velocity.app.VelocityEngine;
    import org.springframework.ui.velocity.VelocityEngineUtils;

    public class MsgBean ...{
        private VelocityEngine velocityEngine;

        private String msg;

        private Map model; // 用來保存velocity中的參數值

        private String encoding; // 編碼

        private String templateLocation; // 注入的velocity模塊

        public String getEncoding() ...{
            return encoding;
        }

        public void setEncoding(String encoding) ...{
            this.encoding = encoding;
        }

        public String getTemplateLocation() ...{
            return templateLocation;
        }

        public void setTemplateLocation(String templateLocation) ...{
            this.templateLocation = templateLocation;
        }

        public Map getModel() ...{
            return model;
        }

        public void setModel(Map model) ...{
            this.model = model;
        }

        public String getMsg() ...{
            // return title;
            // 將參數值注入到模塊后的返回值
            return VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
                    templateLocation, encoding, model);

        }

        public void setMsg(String msg) ...{
            this.msg = msg;
        }

        public VelocityEngine getVelocityEngine() ...{
            return velocityEngine;
        }

        public void setVelocityEngine(VelocityEngine velocityEngine) ...{
            this.velocityEngine = velocityEngine;
        }

    }

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

     

       
     <bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean"> 
       <property name="resourceLoaderPath">
                <value>classpath:velocity</value>
         </property>
        <property name="velocityProperties">
                     <props>
                           <prop key="resource.loader">class</prop>
                           <prop key="class.resource.loader.class">
                                 org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
                           </prop>
                           <prop key="velocimacro.library"></prop>
                           <prop key="input.encoding">GBK</prop>
                           <prop key="output.encoding">GBK</prop>
                           <prop key="default.contentType">text/html; charset=GBK</prop>
                     </props>
               </property>
    </bean>

    <bean id="msgBean" class="MsgBean">
            <property name="templateLocation" value="test.vm"></property>
            <property name="encoding" value="GBK"></property>
            <property name="velocityEngine" ref="velocityEngine"></property>
    </bean>


    </beans>

    import java.io.File;
    import java.io.IOException;
    import java.util.HashMap;
    import java.util.Map;

    import org.apache.commons.io.FileUtils;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;


    public class TestVeloctiy ...{
        public static void main(String[] args) ...{
            // TODO Auto-generated method stub
            ApplicationContext ctx=new ClassPathXmlApplicationContext("test3.xml");
            MsgBean    msgBean=((MsgBean)ctx.getBean("msgBean"));
            Map<String, String> data = new HashMap<String, String>();
            data.put("me","yourname");
            msgBean.setModel(data);
            System.out.println(msgBean.getMsg());
           
            
            //根據apache common IO 組件直接將內容寫到一個文件中去.
             File dest = new File( "test.html" );         
              try ...{
                FileUtils.writeStringToFile( dest, msgBean.getMsg(), "GBK" );
            } catch (IOException e) ...{
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    }

    本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/pengchua/archive/2008/01/17/2049490.aspx

    posted on 2009-11-26 11:36 jimphei 閱讀(1155) 評論(0)  編輯  收藏

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


    網站導航:
     
    主站蜘蛛池模板: 最新国产乱人伦偷精品免费网站| 亚洲天堂福利视频| 边摸边吃奶边做爽免费视频网站| www视频在线观看免费| 亚洲精品无码不卡| 免费一区二区三区| 亚洲va在线va天堂va不卡下载 | 深夜免费在线视频| 亚洲AV无码一区二三区| 香蕉视频在线观看免费| 又黄又大又爽免费视频| 高潮毛片无遮挡高清免费| 免费在线观看视频a| 成年网站免费入口在线观看 | 亚洲国产成人久久精品动漫 | 乱淫片免费影院观看| 亚洲综合另类小说色区色噜噜| 特级毛片免费观看视频| 在线观看国产区亚洲一区成人 | 亚洲综合自拍成人| 日本xxxx色视频在线观看免费| 久久久久亚洲AV无码永不| 99在线在线视频免费视频观看| 亚洲美女激情视频| 桃子视频在线观看高清免费完整| 亚洲综合欧美色五月俺也去| 国产免费看插插插视频| 中文字幕永久免费视频| 久久精品国产亚洲AV电影| 99久久综合国产精品免费| 国产精品亚洲一区二区三区久久 | 亚洲一级特黄大片无码毛片| 三级黄色片免费看| 亚洲人成777在线播放| 国产午夜影视大全免费观看 | 中文字幕免费在线观看| 亚洲乱码av中文一区二区| 国产成人精品曰本亚洲79ren| 久久精品人成免费| 国产亚洲一卡2卡3卡4卡新区| 亚洲夜夜欢A∨一区二区三区|