xml文件中配置
VelocityConfigurer类通过依赖注入在服务层获得此类的实例,如applicationContext.getBean()方法
生成文件的代码例子:
可以生成静态文件example.html
org.springframework.web.servlet.view.velocity.VelocityConfigurer
类,该bean由spring容器管理,在容器启动时加载。该类的
resourceLoaderPath
属性用来配置模板放置的路径。
configLocation
属性配置velocity的properties文件的相对路径,
velocityProperties
属性配置velocity的属性。
VelocityConfigurer类通过依赖注入在服务层获得此类的实例,如applicationContext.getBean()方法
生成文件的代码例子:
VelocityEngine engine = velocityConfigurer.getVelocityEngine();
Template template = engine.getTemplate("example.vm");
Context context = new VelocityContext();
context.put("example", "要传递到模板的对象实例");
PrintWriter pw = new PrintWriter(new File("example.html"));
template.merge(context, pw);
pw.flush();
pw.close();
可以生成静态文件example.html