Spring Thymeleaf Chinese garbled

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.