Objective:
The project was springmvc+thymeleaf, but all the Chinese in the HTML were found to be garbled.
But the encoding of their own HTML is already UTF-8, in the Web. xml file also added Characterencodingfilter, or not resolved.
Search on the internet for a long time, the online version is to add characterencoding properties for Thymeleafviewresolver, but after their own attempts have not been resolved.
Workaround:
Add Characterencoding=utf-8 properties for both Servletcontexttemplateresolver and Thymeleafviewresolver. The code is as follows. (important part is marked in red),
<!--front-end render Magic Board engine Thymeleaf - <BeanID= "Templateresolver"class= "Org.thymeleaf.templateresolver.ServletContextTemplateResolver"> < Propertyname= "prefix"value= "/pages/"/> < Propertyname= "suffix"value= ". html"/> <!--set Thymeleaf to parse the HTML mode - < Propertyname= "Templatemode"value= "LEGACYHTML5"/> < Propertyname= "cacheable"value= "false"/>
<!--here to set the code--<property name= "characterencoding" value= "UTF-8"/> </Bean> <BeanID= "Templateengine"class= "Org.thymeleaf.spring3.SpringTemplateEngine"> < Propertyname= "Templateresolver"ref= "Templateresolver"/> </Bean> <!--Viewresoler of the configuration engine - <Beanclass= "Org.thymeleaf.spring3.view.ThymeleafViewResolver"> < Propertyname= "Templateengine"ref= "Templateengine"/>
<!--here to set the code--
<property name= "characterencoding" value= "UTF-8"/>
</ Bean >
Spring Thymeleaf Chinese garbled