spring Thymeleaf 中文乱码
来源:互联网 发布:清华大学网络 编辑:程序博客网 时间:2024/06/02 06:25
前言:
项目用springmvc+Thymeleaf ,但是发现html中的所有中文都乱码。
但是自己的html的编码确定已经是UTF-8,在web.xml文件里面也添加了CharacterEncodingFilter,还是没有解决。
在网上搜了好久,网上的说法是为ThymeleafViewResolver添加characterEncoding的属性,但是自己尝试之后还是没有解决。
解决办法:
同时为ServletContextTemplateResolver和ThymeleafViewResolver添加characterEncoding=UTF-8的属性。代码如下。(重要部分红色标出了)、
<!-- 前端的渲染魔板引擎thymeleaf--> <bean id="templateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver"> <property name="prefix" value="/pages/"/> <property name="suffix" value=".html"/> <!-- 设置thymeleaf可以解析html的mode--> <property name="templateMode" value="LEGACYHTML5"/> <property name="cacheable" value="false"/> <!--这里要设置编码 --> <property name="characterEncoding" value="UTF-8"/> </bean> <bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine"> <property name="templateResolver" ref="templateResolver"/> </bean> <!-- 配置引擎的viewResoler--> <bean class="org.thymeleaf.spring3.view.ThymeleafViewResolver"> <property name="templateEngine" ref="templateEngine"/>
<!--这里要设置编码 --> <property name="characterEncoding" value="UTF-8"/>
</bean>
0 0
- spring thymeleaf 中文乱码
- spring Thymeleaf 中文乱码
- spring thymeleaf中文乱码问题
- thymeleaf + titles + Spring MVC 中文乱码
- thymeleaf中文乱码问题
- thymeleaf中文乱码问题
- springmvc整合thymeleaf中文乱码
- Thymeleaf中文乱码问题,热部署问题
- spring+Thymeleaf中文编码的问题
- spring+thymeleaf
- Spring 中文乱码
- spring 参数中文乱码
- spring mvc中文乱码
- Spring+Mysql中文乱码
- spring中文乱码问题
- spring 中文乱码解决办法
- spring mvc 中文乱码
- spring mvc 中文乱码
- android apk 签名
- android反编译工具总结
- 调度算法解析
- visualstudiocode 调试electron
- 多线程
- spring Thymeleaf 中文乱码
- intellij 编译 springmvc+hibernate+spring+maven 找不到hbm.xml映射文件
- intellij创建maven web项目
- zynq中使用FreeRTOS的空闲钩子函数时在SDK中的设置
- python2.7 Unable to find vcvarsall.bat
- Linux服务-vsftp
- 数据结构实验之链表三:链表的逆置
- POJ 2377 (最大生成树 Kruskal)
- android studio下ndk开发