美文网首页spring Thymeleaf
Thymeleaf: replace newline chara

Thymeleaf: replace newline chara

作者: 召唤宠物小精灵 | 来源:发表于2016-08-03 13:18 被阅读514次

${#strings.replace(desc, '\n', '<br />')}

关于不工作的原因有以下两个问题

  • \n是由底层的表达式语言,在模板框架中被认为是两个独立的字符串,不是换行符号
  • thymeleaf 中 <>

解决方案

  • 利用系统的换行符
  • <> 更换为 &lt;&gt;

代码实现

  • 方案1
    ${#strings.replace(desc,T(System).getProperty('line.separator'),'&lt;br/&gt;')}
  • 方案2
    ${#strings.replace(desc,T(org.apache.commons.lang3.StringUtils).LF,'&lt;br/&gt;')}

原文链接

相关文章

网友评论

    本文标题:Thymeleaf: replace newline chara

    本文链接:https://www.haomeiwen.com/subject/duzsjttx.html