I use Thymeleaf 3.0.3 with Spring Boot 1.5.1 and STS Bundle 3.8.1. My Hungarian non-ASCII characters are not shown properly. I have the following configuration in the application.properties file:
spring.thymeleaf.cache=false
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=utf-8
These are anyway the defaults but I wanted to be sure that my Thymeleaf is configured properly.
My web page charset is also utf-8 and my text editor in Eclipse as well. So how can it happen that I see "�r�l�k, hogy �jra itt vagy Roland" instead of the expected: "Örülök, hogy újra itt vagy Roland"?
You need to set encoding in the viewResolver
@Bean
public ThymeleafViewResolver thymeleafViewResolver(){
ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
viewResolver.setTemplateEngine(templateEngine());
viewResolver.setCharacterEncoding("UTF-8");
return viewResolver;
}
I had same problem. I have found solution, that workerd for me:
You need to save the file as Encode in UTF-8 without BOM. It works for me. Steps: 1. Edit the file in notepad++ and have a copy of these content in one more file. 2. Go to menu Encoding and choose Encode in UTF-8 without BOM. 3. If your file shows some char like xE9 etc., then copy original content to your file and save. 4. Close and re-open the file and check the encoding remains same as "Encode in UTF-8 without BOM". If encoding default to Encode in AnsII that means you had few chars which are like "xE9" and your file didn't saved as Encode in UTF-8 without BOM. 5. If encode remains "Encode in UTF-8 without BOM". 6. Run your application and you could able to see the translated content.
http://forum.thymeleaf.org/UTF-8-encoding-problem-using-messages-properties-in-Spring-Boot-with-Thymeleaf-td4030339.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With