Velocity case (Simple Hello)

Source: Internet
Author: User

Of course, looking for cases of the big people generally want to go directly to a case on the line, not a lot of time to read a lot of text, so not long-winded.

One of course first to download velocity required jar bag, everywhere there are downloads of course I'm going to the official download, after all, the official things are generally more formal

To say the Apache official, think of just start out to work in the basic daily in the official Apache website click less than 50 times. Open source is a lot of things, although the English is rather rotten. But see more

Later found that it is so simple so here I suggest that the best to read the English document, see more of the truth is the same.

Address http://velocity.apache.org/download.cgi I downloaded the latest version Velocity-1.7.zip

Two new Java project my project name here is Velocityexample, then create a new package named Com.qiailin.example, and create a new class under the package Velocityexample.java

[Java]  View plain copy print? package com.qiailin.example;      import java.io.stringwriter;   Import  org.apache.velocity.Template;   import org.apache.velocity.velocitycontext;   import org.apache.velocity.app.velocity;   import org.apache.velocity.app.velocityengine;   /**   * 2011 Year January 14  13:23:13   *  @author   paint Erlend    *  VelocityExample    * Email:qiailing.ok@163.com   * qq 172794299    */   public class velocityexample {           /**       *  @param  args        */       public static void main (String[] args)  {            new velocityexample (). VelociTyclassloadexample ();       }                     public void velocityclassloadexample ()  {           //  Create engine               velocityengine ve=new velocityengine ();               //Set the template load path, which is set under class                ve.setproperty (velocity.resource_loader,  " Class ");              ve.setproperty (" Class.resource.loader.class ", " Org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader ");               try {                    //initialization Operations                    ve.init ();                   //load template, set template coding                   template t=ve.gettemplate (" QIAILIN.VM "," GBK ");                   //Set initialization data                    velocitycontext context = new velocitycontext ();                   context.put ("name",  "John");                    Context.put ("project",  Velo)City ");                  / /Set Output                    Stringwriter writer = new stringwriter ();                   //the environment data into the output                    t.merge (Context, writer);       &nbs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.