关于spring boot使用velocity作为视图层模板
2017-07-22 23:05
971 查看
1、maven配置
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- spring boot 对velocity的支持只到1.4.x -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-velocity</artifactId>
</dependency>
</dependencies>
2、application.properties配置
spring.velocity.cache= true
spring.velocity.charset=UTF-8
spring.velocity.check-template-location=true
spring.velocity.content-type=text/html
spring.velocity.enabled=true
spring.velocity.resource-loader-path=/WEB-INF/views
spring.velocity.prefix=/
spring.velocity.suffix=.vm
spring.velocity.toolbox-config-location=/WEB-INF/toolbox.xml
3、controller相关代码
@Controller
@RequestMapping
public class IndexController {
@RequestMapping("/index")
public String index() {
return "index";
}
}
注意:在我使用1.4.7版本的spring boot时,始终无法将controller的index方法返回的“index”作为视图名称去解析,而是将其用作url地址跳转,最终抛出异常:
javax.servlet.ServletException: Circular view path [index]: would dispatch back to the current handler URL [/demo/index] again. Check your ViewResolver setup! (Hint:
This may be the result of an unspecified view, due to default view name generation.)
网上查阅了一些资料后,我怀疑是spring boot的版本问题导致该问题的发生。于是将spring boot版本降级至1.4.2,尝试启动项目后,发现一切正常,问题已解决。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- spring boot 对velocity的支持只到1.4.x -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-velocity</artifactId>
</dependency>
</dependencies>
2、application.properties配置
spring.velocity.cache= true
spring.velocity.charset=UTF-8
spring.velocity.check-template-location=true
spring.velocity.content-type=text/html
spring.velocity.enabled=true
spring.velocity.resource-loader-path=/WEB-INF/views
spring.velocity.prefix=/
spring.velocity.suffix=.vm
spring.velocity.toolbox-config-location=/WEB-INF/toolbox.xml
3、controller相关代码
@Controller
@RequestMapping
public class IndexController {
@RequestMapping("/index")
public String index() {
return "index";
}
}
注意:在我使用1.4.7版本的spring boot时,始终无法将controller的index方法返回的“index”作为视图名称去解析,而是将其用作url地址跳转,最终抛出异常:
javax.servlet.ServletException: Circular view path [index]: would dispatch back to the current handler URL [/demo/index] again. Check your ViewResolver setup! (Hint:
This may be the result of an unspecified view, due to default view name generation.)
网上查阅了一些资料后,我怀疑是spring boot的版本问题导致该问题的发生。于是将spring boot版本降级至1.4.2,尝试启动项目后,发现一切正常,问题已解决。
相关文章推荐
- SpringBoot使用JSP作为视图模板
- SpringBoot使用JSP作为视图模板的方法
- Spring Boot 与 Kotlin使用Freemarker模板引擎渲染web视图
- spring boot 使用velocity、freeMarker模板创建html页面返回给前端
- 关于在spring boot中使用默认的 thymeleaf模板
- 【推荐】Springboot使用velocity模板引擎
- 关于在spring boot里使用Thymeleaf模板的application.properties配置
- spring boot 使用velocity、freeMarker模板创建html页面返回给前端
- springboot使用velocity模板乱码问题
- 一头扎进springboot之使用Freemarker模板引擎渲染web视图
- Spring Boot☞ 使用Thymeleaf模板引擎渲染web视图
- Spring Boot 与 kotlin 使用Thymeleaf模板引擎渲染web视图的方法
- Spring Boot☞ 使用velocity渲染web视图
- 深入学习spring-boot系列(三)--使用thymeleaf模板
- 深入学习spring-boot系列(三)--使用thymeleaf模板
- 深入学习spring-boot系列(三)--使用thymeleaf模板
- 深入学习spring-boot系列(三)--使用thymeleaf模板
- 深入学习spring-boot系列(三)--使用thymeleaf模板
- 深入学习spring-boot系列(三)--使用thymeleaf模板
- 深入学习spring-boot系列(三)--使用thymeleaf模板