描述:使用thymeleaf生成的html頁面中文顯示亂碼。檢查過項目的設置,都已經改成UTF-8。但是查看html相關請求的響應頭中,content_type仍然是ISO-8859-1.
解決方法:查資料發現,是thymeleaf框架的問題,需要在配置文件設置html的編碼。問題解決。
<bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
<property name="templateEngine" ref="templateEngine" />
<!-- NOTE 'order' and 'viewNames' are optional -->
<property name="order" value="1" />
<property name="characterEncoding" value="UTF-8" />
<property name="viewNames" value="*.html,*.xhtml" />
</bean>
相關資料:https://www.cnblogs.com/peak-c/archive/2015/10/18/4890150.html