【问题标题】:Thymeleaf encoding issueThymeleaf 编码问题
【发布时间】:2017-08-10 00:55:36
【问题描述】:

我将 Thymeleaf 3.0.3 与 Spring Boot 1.5.1 和 STS Bundle 3.8.1 一起使用。我的匈牙利语非 ASCII 字符显示不正确。 我在 application.properties 文件中有以下配置:

spring.thymeleaf.cache=false
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=utf-8

这些都是默认设置,但我想确保我的 Thymeleaf 配置正确。

我的网页字符集也是 utf-8,我在 Eclipse 中的文本编辑器也是如此。那么,我怎么会看到“...

【问题讨论】:

  • 你的问题解决了吗?

标签: spring-boot utf-8 thymeleaf


【解决方案1】:

我有同样的问题。我找到了为我工作的解决方案:

您需要将文件保存为 UTF-8 编码,无需 BOM。这个对我有用。 脚步: 1. 在 notepad++ 中编辑文件,并在另一个文件中复制这些内容。 2. 转到菜单编码并选择在没有 BOM 的 UTF-8 中编码。 3. 如果您的文件显示一些字符,如 xE9 等,则将原始内容复制到您的文件并保存。 4. 关闭并重新打开文件,检查编码是否与“Encode in UTF-8 without BOM”相同。 如果编码默认为 AnsII 中的编码,则意味着您的字符很少,例如“xE9”,并且您的文件没有保存为没有 BOM 的 UTF-8 编码。 5. 如果 encode 仍然是“Encode in UTF-8 without BOM”。 6. 运行您的应用程序,您可以看到翻译后的内容。

http://forum.thymeleaf.org/UTF-8-encoding-problem-using-messages-properties-in-Spring-Boot-with-Thymeleaf-td4030339.html

【讨论】:

    【解决方案2】:

    需要在viewResolver中设置编码

    @Bean
    public ThymeleafViewResolver  thymeleafViewResolver(){
        ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
        viewResolver.setTemplateEngine(templateEngine());
        viewResolver.setCharacterEncoding("UTF-8");
        return viewResolver;
    }
    

    【讨论】:

      猜你喜欢
      • 2019-10-02
      • 2013-12-16
      • 2021-07-28
      • 1970-01-01
      • 2016-01-08
      • 2015-10-11
      • 2011-04-13
      • 2017-11-10
      • 1970-01-01
      相关资源
      最近更新 更多