2016-04-04 182 views

回答

10

答案可以發現here

物業characterEncodingtemplateResolverThymeleafViewResolver明確設置:

<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> 
-1

我覺得在thymeleaf HTML頁面使用的是日:與HTML元素的文本,日:文本只是顯示正常文本,

如果你想使用特殊的章程與你的thymeleaf html頁面,所以只需要改變例如

日:utext = 「$ {yourcontroller_var}」

日:utext = 「#{properties_var}」

例如

<div th:utext="${user.name}"> Test! </div> // for your controller variable 

And

<div th:utext="#{message.username}"> UserName! </div> // for your properties variable 

沒有其他配置使用thymeleaf html頁面使用特殊字符。

希望你解決您的問題

+0

你錯了,當頁面有靜態文本和文件是'UTF-8'編碼這不會解決問題。 – Andremoniy

+0

@Andremoniy什麼可以解決這個問題? –

+0

https://stackoverflow.com/a/36397227/1479414 – Andremoniy