Thymeleaf【第一篇】 结合springmvc
来源:互联网 发布:仙剑传奇网站源码 编辑:程序博客网 时间:2024/05/30 04:40
1.Maven配置
<dependency> <groupId>org.thymeleaf</groupId> <artifactId>thymeleaf</artifactId> <version>3.0.6.RELEASE</version> </dependency> <dependency> <groupId>org.thymeleaf</groupId> <artifactId>thymeleaf-spring4</artifactId> <version>3.0.6.RELEASE</version> </dependency>
2.配置Thymeleaf相关bean
<!-- 定义Thymeleaf视图解析器 负责将逻辑视图名解析为的Thymeleaf模板视图--> <bean id="viewResovler" class="org.thymeleaf.spring4.view.ThymeleafViewResolver"> <property name="templateEngine" ref="templateEngine"></property> <property name="characterEncoding" value="utf-8"></property> </bean> <!-- 定义SpringTemplateEngine 模板引擎 处理模板并输出渲染结果--> <bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine"> <property name="templateResolver" ref="templateResolver"></property> </bean> <!-- -定义TemplateResolver模板解析器 用来加载Thymeleaf模板--> <bean id="templateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver"> <constructor-arg ref="servletContext"/> <property name="prefix" value="/WEB-INF/"></property> <property name="suffix" value=".html"></property> <property name="templateMode" value="HTML5"></property> <property name="characterEncoding" value="utf-8"></property> </bean> <bean id="servletContext" class="utils.ServletContextFactory"></bean>
Tips:
1.上面的配置中,servletContextViewResovler创建时,需要传一个构造器参数servletContext?
答: 在xml文件中,我们怎么引入servletContext呢?
请参考How to set ServletContext property for a bean in Spring XML metadata configuration
2.访问thymeleaf模板生成的页面时,发现中文乱码,该怎么解决?
答:在viewResolver和templateResovler中分别注入characterEncoding为utf-8
阅读全文
0 0
- Thymeleaf【第一篇】 结合springmvc
- springmvc第一篇
- SpringBoot的Thymeleaf支持,结合SpringMVC做的案例(学习SpringBoot实战)
- SpringMVC整合Thymeleaf模板
- SpringMVC:集成Thymeleaf
- SpringMVC 配置Thymeleaf模板
- SpringMVC配置Thymeleaf
- SpringMVC 第一篇【万能的Hello World】
- springMVC+spring+maven+mybatis第一篇配置
- 结合thymeleaf js取值
- springmvc整合thymeleaf中文乱码
- SpringMVC(Thymeleaf)向JQuery传参
- spring+springmvc+hibernate+thymeleaf 练习
- spring+springmvc+jpa+thymeleaf 练习
- spring+springmvc+mybatis+thymeleaf练习
- 简单的springMvc用myeclipse使用流程第一篇
- SpringMVC第一篇【介绍、入门、工作流程、控制器】
- 【第一篇】搞定BootstrapTable(后端使用SpringMVC+Hibernate)
- 动态规划 硬币 POJ
- oracle 查询表数据慢,暂时解决方法
- Android 进程保活资料汇总与华为白名单那些事
- 慎用zoom属性
- android mvp模式讲解
- Thymeleaf【第一篇】 结合springmvc
- Spring4学习笔记(三):依赖注入的方式与细节
- 详解最大似然估计(MLE)、最大后验概率估计(MAP),以及贝叶斯公式的理解
- [Web]Jquery圆点的图片轮播
- File-OS(简单文件系统的实现)
- [leetcode]: 9. Palindrome Number
- i miss you
- sublime text3中中文件名显示为方框,如何解决?
- Kotlin Reference (二) idioms 一些常用方式