Thymeleaf模板与Spring MVC集成
2017-12-21 17:02
302 查看
Thymeleaf 定义了 org.thymeleaf.spring4.view.ThymeleafView 和 org.thymeleaf.spring4.view.ThymeleafViewResolver(默认使用ThymeleafView 作为 View)。Thymeleaf 提供了一个SpringTemplateEngine 类,用来驱动在 Spring MVC 下使用
Thymeleaf 模板引擎,还提供了一个 TemplateResolver 来设置通用的模板引擎(包括前缀、后缀等),在 Spring MVC中集成Thymeleaf 引擎很简单。示例:
Thymeleaf 模板引擎,还提供了一个 TemplateResolver 来设置通用的模板引擎(包括前缀、后缀等),在 Spring MVC中集成Thymeleaf 引擎很简单。示例:
package com.example.demo; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.thymeleaf.spring4.SpringTemplateEngine; import org.thymeleaf.spring4.view.ThymeleafView; import org.thymeleaf.spring4.view.ThymeleafViewResolver; import org.thymeleaf.templateresolver.ServletContextTemplateResolver; import org.thymeleaf.templateresolver.TemplateResolver; /** * Created by Administrator on 2017/12/21. */ @Configuration public class ConfigApplication { @Bean public TemplateResolver templateResolver() { TemplateResolver templateResolver = new ServletContextTemplateResolver(); templateResolver.setPrefix("/WEB-INF/templates"); templateResolver.setSuffix(".html"); templateResolver.setTemplateMode("HTML5"); return templateResolver; } @Bean public SpringTemplateEngine templateEngine() { SpringTemplateEngine templateEngine = new SpringTemplateEngine(); templateEngine.setTemplateResolver(templateResolver()); return templateEngine; } @Bean public ThymeleafViewResolver thymeleafViewResolver() { ThymeleafViewResolver thymeleafViewResolver = new ThymeleafViewResolver(); thymeleafViewResolver.setTemplateEngine(templateEngine()); thymeleafViewResolver.setViewClass(ThymeleafView.class); return thymeleafViewResolver; } }
相关文章推荐
- spring mvc 集成velocity模板
- 在Spring MVC和Spring Boot中使用thymeleaf模板
- springboot 入门教程(4)--web开发(spring mvc和Thymeleaf模板,带源码)
- 在Spring Boot中集成Thymeleaf模板引擎
- Spring MVC : Java模板引擎 Thymeleaf (二)
- spring mvc 集成velocity模板
- Spring MVC : Java模板引擎 Thymeleaf (二)
- Spring MVC : Java模板引擎 Thymeleaf
- Spring MVC与thymeleaf模版引擎集成的简单例子
- Spring MVC 集成 Thymeleaf
- Java集成thymeleaf视图层模板引擎构建web项目实例讲解(附项目源码)
- Spring MVC : Java模板引擎 Thymeleaf (三)
- Spring MVC : Java模板引擎 Thymeleaf (三)
- spring mvc 集成freemarker模板
- spring mvc 集成 thymeleaf ----注解
- Spring MVC : Java模板引擎 Thymeleaf (一)
- spring mvc 集成freemarker模板
- Spring MVC中使用Thymeleaf模板引擎
- Spring MVC集成thymeleaf时提示:defined in ServletContext resource [/WEB-INF/SrpingMVCTest-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException
- spring-thymeleaf 集成报错