Thymeleaf:EL1043E:意外的令牌

Thymeleaf: EL1043E: Unexpected token

我有一段代码的百里香:

<p th:utext="${#strings.replace( #strings.escapeXml( user.text ),${lineSeparator},'&lt;br /&gt;')}" >
                                Presentación
                            </p>

在控制器中:

model.addAttribute("lineSeparator", System.lineSeparator());

但是当我访问页面时出现这个错误:

05:38:22.290 [http-nio-7080-exec-8] ERROR org.apache.juli.logging.DirectJDKLog.log 175 - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing faile
d; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "#strings.replace( #strings.escapeXml( user.text ),${lineSeparator},'<br />')" (temp
late: "user" - line 217, col 11)] with root cause
org.springframework.expression.spel.SpelParseException: Expression [#strings.replace( #strings.escapeXml( user.text ),${lineSeparator},'<br />')] @52: EL1043E: Unexpected token. Expected 'rparen())' but 
was 'lcurly({)'

您不能在不进行预处理的情况下嵌套 ${...} 表达式(在大多数情况下,除非您正在进行预处理,否则您永远不需要这样做)。删除 lineSeparator 周围的 ${...}

<p th:utext="${#strings.replace(#strings.escapeXml(text), lineSeparator,'&lt;br /&gt;')}" >
  Presentación
</p>