thymeleaf 模板类 - 无法解析为表达式

问题描述 投票:0回答:1

我有这个工作正常的模板:

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="x-ua-compatible" content="ie=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="shortcut icon" th:href="@{/images/logo.png}" type="image/x-icon"/>
    <title>Mystic River</title>
    <link rel="stylesheet" th:href="@{/css/style.css}" />
    <link rel="stylesheet" th:href="@{/css/responsive.css}" />
  </head>
  <body>
    <!-- Header -->
    <header class="header-wrapper header_fixed bg_transparent" id="header-wrapper">
....
</html>

但是使用时

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="x-ua-compatible" content="ie=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="shortcut icon" th:href="@{/images/logo.png}" type="image/x-icon"/>
   <title>Mystic River</title>
    <link rel="stylesheet" th:href="@{/css/style.css}" />
    <link rel="stylesheet" th:href="@{/css/responsive.css}" />
  </head>
  <body>
    <!-- Header -->
    <header th:class="header-wrapper header_fixed bg_transparent" id="header-wrapper">

我有这个错误:

Caused by: org.attoparser.ParseException: Could not parse as expression: "header-wrapper header_fixed bg_transparent" (template: "index" - line 14, col 13)
    at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393)
    at org.attoparser.MarkupParser.parse(MarkupParser.java:257)
    at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230)
    ... 48 more
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "header-wrapper header_fixed bg_transparent" (template: "index" - line 14, col 13)
    at org.thymeleaf.standard.expression.StandardExpressionParser.parseExpression(StandardExpressionParser.java:131)
    at org.thymeleaf.standard.expression.StandardExpressionParser.parseExpression(StandardExpressionParser.java:62)
    at org.thymeleaf.standard.expression.StandardExpressionParser.parseExpression(StandardExpressionParser.java:44)
thymeleaf spring-thymeleaf
1个回答
0
投票

你有

class="header-wrapper header_fixed bg_transparent"

在第一个模板中并且

th:class="header-wrapper header_fixed bg_transparent"

在第二个(注意

th:class
而不是
class
)。
"header-wrapper header_fixed bg_transparent"
不是有效的 Thymeleaf 表达式。

© www.soinside.com 2019 - 2024. All rights reserved.