Spring MVC 集成 Thymeleaf
来源:互联网 发布:编写app需要什么软件 编辑:程序博客网 时间:2024/04/28 07:00
使用不同的视图模板需要配置三个内容:
- 视图解析器,根据逻辑视图名解析正确的模板视图
- 模板引擎,处理模板视图并渲染结果
- 模板解析器,加载模板
注意:Thymeleaf 默认的 page encoding 不是 UTF-8,如果要使用UTF-8 编码页面,必须进行相关设置
@Configuration@EnableWebMvc@ComponentScan(basePackages = "com.workfun.web")public class WebConfig extends WebMvcConfigurerAdapter implements ApplicationContextAware { private ApplicationContext applicationContext; public WebConfig() { super(); } @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; } //访问静态资源 @Override public void addResourceHandlers(final ResourceHandlerRegistry registry) { super.addResourceHandlers(registry); registry.addResourceHandler("/images/**").addResourceLocations("/images/"); registry.addResourceHandler("/css/**").addResourceLocations("/css/"); registry.addResourceHandler("/js/**").addResourceLocations("/js/"); } @Bean public SpringResourceTemplateResolver templateResolver() { // SpringResourceTemplateResolver automatically integrates with Spring's own // resource resolution infrastructure, which is highly recommended. SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver(); templateResolver.setApplicationContext(this.applicationContext); templateResolver.setPrefix("/WEB-INF/templates/"); templateResolver.setSuffix(".html"); // HTML is the default value, added here for the sake of clarity. templateResolver.setTemplateMode(TemplateMode.HTML); // recource encoding templateResolver.setCharacterEncoding("UTF-8"); // Template cache is true by default. Set to false if you want // templates to be automatically updated when modified. templateResolver.setCacheable(true); return templateResolver; } @Bean public SpringTemplateEngine templateEngine() { // SpringTemplateEngine automatically applies SpringStandardDialect and // enables Spring's own MessageSource message resolution mechanisms. SpringTemplateEngine templateEngine = new SpringTemplateEngine(); templateEngine.setTemplateResolver(templateResolver()); // Enabling the SpringEL compiler with Spring 4.2.4 or newer can // speed up execution in most scenarios, but might be incompatible // with specific cases when expressions in one template are reused // across different data types, so this flag is "false" by default // for safer backwards compatibility. templateEngine.setEnableSpringELCompiler(true); return templateEngine; } @Bean public ThymeleafViewResolver viewResolver() { ThymeleafViewResolver viewResolver = new ThymeleafViewResolver(); viewResolver.setTemplateEngine(templateEngine()); // pageEncoding , very important viewResolver.setCharacterEncoding("UTF-8"); return viewResolver; }}
阅读全文
0 0
- Thymeleaf MVC 集成Spring
- Spring MVC 集成 Thymeleaf
- spring mvc 集成 thymeleaf ----注解
- Thymeleaf MVC与Spring的集成
- Thymeleaf模板与Spring MVC集成
- Spring MVC与thymeleaf模版引擎集成的简单例子
- Spring集成Thymeleaf
- spring-boot集成thymeleaf
- Spring MVC Thymeleaf
- spring mvc 配置 thymeleaf
- Thymeleaf系列一 Spring boot 集成Thymeleaf
- Spring Boot与Thymeleaf集成
- Spring MVC + thymeleaf 非配置
- spring Boot 集成 Thymeleaf模板引擎实例
- spring spring mvc集成
- Spring MVC view layer: Thymeleaf vs. JSP
- thymeleaf + titles + Spring MVC 中文乱码
- Spring MVC with Thymeleaf HTML template pages
- 了解Webhooks
- JPA规范与ORM框架之间的关系是怎样的呢?
- AngularJs的POST
- 在CentOS7.4中安装jdk的几种方法及配置环境变量
- http://blog.csdn.net/azhengye
- Spring MVC 集成 Thymeleaf
- 利用react-native构建一个新项目
- 三.zookeeper的zoo.cfg配置详解
- JMS基本概念
- 相机标定实验过程注意问题及总结
- .Net c#:配置引用程序集的路径(分离exe和dll从指定路径调用)
- elasticsearch-6.0.1 笔记
- Makefile 中:= ?= += =的区别
- 实验6-7