You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Thymeleaf无法渲染项目符号求助:显示为问号

解决Thymeleaf项目符号显示为问号的问题

以下是几个可行的修复方案:

  • 直接在表达式中插入Unicode符号
    无需通过后端传变量,直接在Thymeleaf的th:utext表达式里写入Unicode编码的项目符号,代码示例:

    <h2 class="dates" th:utext="${month} + ' ' + ${dateOne} + ' ' + ${dateTwo} + '\u2022' + ${dateThree} + ', ' + ${year}"></h2>
    
  • 确保页面与后端编码统一为UTF-8

    • 在HTML页面头部添加字符编码声明:
      <meta charset="UTF-8">
      
    • 后端(如Spring Boot)配置文件中添加编码设置:
      spring.http.encoding.charset=UTF-8
      spring.http.encoding.enabled=true
      spring.http.encoding.force=true
      
  • 直接在模板中使用实体符号或原生符号
    放弃通过表达式拼接,直接在模板里写入项目符号实体或原生符号,结合Thymeleaf内联文本:

    <h2 class="dates">[[${month}]] [[${dateOne}]] [[${dateTwo}]] &bull; [[${dateThree}]], [[${year}]]</h2>
    

    或者直接写原生符号:

    <h2 class="dates">[[${month}]] [[${dateOne}]] [[${dateTwo}]] • [[${dateThree}]], [[${year}]]</h2>
    
  • 检查后端传入变量的编码正确性
    如果坚持通过${bullet}传值,后端生成该变量时必须使用UTF-8编码的字符串,Java代码示例:

    model.addAttribute("bullet", "\u2022");
    

    避免使用其他编码格式的字符串导致转码错误。

内容的提问来源于stack exchange,提问作者kyleryan1291

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 21:12:38