Spring boot using the velocity template

Source: Internet
Author: User


(Do not use this template, the latest version of spring boot is not supported.) Use Freemarker bar: http://blog.csdn.net/clementad/article/details/51942629)


In a few simple steps, use the velocity template to generate text in spring boot:


1. Introduction of Dependency


<dependency>  
<groupId>org.springframework.boot</groupId>
<artifactId> Spring-boot-starter-velocity</artifactid>
</dependency>


2. Create templates directory in Resources 


3. Create a. VM template file Welcome.vm: 


 4, use the template, test cases: 
 
@Autowired
velocityengine velocityengine;

@Test public
void Velocitytest () {
map<string, object> model = new hashmap<string, object> ();
Model.put ("Time", xdateutils.nowtostring ());
Model.put ("message", "This is the content of the test ... ");
Model.put ("Tousername", "Zhang San");
Model.put ("Fromusername", "Lao Xu");
System.out.println (velocityengineutils.mergetemplateintostring (Velocityengine, "WELCOME.VM", "UTF-8", model));


 5. Test results: 

Report:
 Velocity Official Website: http://velocity.apache.org/

Velocity Syntax Reference: http://velocity.apache.org/engine/devel/vtl-reference.html

Source Code Reference: Https://github.com/xujijun/my-spring-boot

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.