(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