springboot 集成velocity 配置

springboot 高版本已经放弃对velocity的支持。1.4.2版本之前可以集成使用。如果想要高版本使用需要自己配置。

pom.xml  使用velocity

    org.springframework.boot

    spring-boot-starter-velocity

然后加入velocity配置即可使用:

/** * velocity 配置 * @return */

@Bean

public VelocityConfig velocityConfig() {                                                                                                                                                        VelocityConfigurer config = new VelocityConfigurer();                                                                                                      config.setResourceLoaderPath("/templates/");                                                                                                                                                      Properties velocityProperties = new Properties();                                                                                                          velocityProperties.put("output.encoding", "UTF-8");                                                                                                                      velocityProperties.put("input.encoding", "UTF-8");                                                                                          config.setVelocityProperties(velocityProperties);                                                                                                                                                    return config;                                                                                                                                                                                                                                        }

/** * 配置视图解析器 * @return */                                                                                                                                                                                                                            @Bean                                                                                                                                                                                                                   public VelocityLayoutViewResolver viewResolver(){                                                                                                                                                  VelocityLayoutViewResolver viewResolver= new VelocityLayoutViewResolver(); //配置的是项目编译之后,视图所在的路径     viewResolver.setPrefix("/templates/");                                                                                                                                                                    viewResolver.setSuffix(".vm");                                                                                                                                                          viewResolver.setViewClass(VelocityLayoutView.class);                                                                                          viewResolver.setLayoutUrl("/templates/layout/layout.vm");                                                                                  viewResolver.setContentType("text/html;charset=UTF-8");                                                                                  viewResolver.setToolboxConfigLocation("/WEB-INF/classes/config/toolbox.xml");                                                                                                return viewResolver ;                                                                                                                                                                                             }


路径

你可能感兴趣的:(springboot 集成velocity 配置)