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 --> <bean class= "Org.thymeleaf.spring3.view.ThymeleafViewResolver" > <property Span style= "color: #ff0000;" >name= "Templateengine" ref = "Templateengine" />
<!--here to set the code--
<property name= "characterencoding" value= "UTF-8"/>
</Bean>
Spring Thymeleaf Chinese garbled