utf8字符集与Thymeleaf [英] utf8 charset with Thymeleaf
本文介绍了utf8字符集与Thymeleaf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将Spring与Thymeleaf一起使用时,我所有的西里尔字母都在页面上显示为?????
.
When using Spring with Thymeleaf all my Cyrillic characters are shown as ?????
on pages.
使用
@RequestMapping(value = "/login", method = RequestMethod.GET, produces = "text/html; charset=utf-8")
如此处建议的那样: https://stackoverflow.com/a/11866822/1479414 以及此处: https://stackoverflow.com/a/12023816/1479414 无效.
as it was suggested here: https://stackoverflow.com/a/11866822/1479414 and here: https://stackoverflow.com/a/12023816/1479414 doesn't help.
如何解决此问题?
推荐答案
可以找到答案属性characterEncoding
应该为templateResolver
和ThymeleafViewResolver
明确设置:
Property characterEncoding
should be explicitly set for templateResolver
and ThymeleafViewResolver
:
<bean id="templateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
...
<property name="characterEncoding" value="UTF-8"/>
...
</bean>
<bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
...
<property name="characterEncoding" value="UTF-8"/>
...
</bean>
这篇关于utf8字符集与Thymeleaf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文