Nvelocity template engine, Basic Experience, very useful stuff.

Source: Internet
Author: User
Use of nvelocity.
First: Download a NVelocity-0.4.1.zip on http://nvelocity.sourceforge.net/
In the bin directory under it, you can find nvelocity. dll (which will be used in the net project) and introduce it to the project ....
First, introduce the following namespace:
Using Commons. collections;
Using Nvelocity;
Using Nvelocity. app;
Using Nvelocity. context;
Step 1: Creating a velocityengine is to create a velocityengine instance.
Velocityengine velocity = New Velocityengine (); // you can also use a constructor with parameters for direct instances.
Extendedproperties props = New Extendedproperties ();
Velocity. INIT (props );

Step 2: creating the template to load the Template File
In this case, the template class is used and the template is loaded using the gettemplate method of velocityengine.
Template template = velocity. gettemplate (@ "Path/to/myfirsttemplate. VM");

Step 3: merging the template integration template
Velocitycontext context =NewVelocitycontext ();
Context. Put ("From","Somewhere");
Context. Put ("","Someone");
Context. Put ("Subject","Welcome to nvelocity");
Context. Put ("Customer",NewCustomer ("John Doe"));

Step 4: Create an IO stream to output the template content. Stringwriter is recommended (because the template is stored as a string)
Stringwriter writer =NewStringwriter ();
Template. Merge (context, writer );
Response. Write (writer. tostring ());

--- Through the above steps, you can easily use the nvelocity template engine technology.
Have you found the final response. Write (writer. tostring ())?

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.