【问题标题】:Spring Boot + Thymeleaf: How to keep line breaks from localization stringsSpring Boot + Thymeleaf:如何保持本地化字符串中的换行符
【发布时间】:2016-06-15 20:50:36
【问题描述】:

我有带换行符的本地化字符串:

label.example=Text\nwith\nline\nbreaks

我使用 thymeleaf 设置文本:

th:text="#{label.example}"

但文本打印如下:

Text with line breaks

但我希望文本看起来像

Text
with
line
breaks

为什么我的\n 全部被删除而不是呈现为换行符?我怎样才能保持我的换行符?这真的很重要。

【问题讨论】:

    标签: spring thymeleaf


    【解决方案1】:

    因为 HTML 将一系列空格字符(包括换行符)视为单个空格。除非你告诉它使用 CSS 保留换行符。

    white-space property

    【讨论】:

    • 为我工作,也避免使用像 th:utext 之类的东西(我不喜欢因为代码执行)。
    猜你喜欢
    • 2021-08-02
    • 1970-01-01
    • 2020-08-05
    • 2023-03-24
    • 1970-01-01
    • 2016-11-22
    • 2017-06-23
    • 2016-12-17
    • 2011-09-18
    相关资源
    最近更新 更多