【发布时间】:2020-04-04 01:07:42
【问题描述】:
我有返回对象列表的 Spring Boot 控制器,我正在使用 thymeleaf 显示 html 中的记录,代码如下:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="ISO-8859-1">
<title>AllRecords</title>
</head>
<body>
<h3>Showing all records</h3>
<table border="1">
<tr>
<td>Title</td>
<td>Publised At</td>
<td>Author</td>
</tr>
<tr th:each="news : ${newsList}">
<td th:text="${news?.title}">Title</td>
<td th:text="${news.publishedAt}">Publised At</td>
<td th:text="${news?.author}">Author</td>
</tr>
</table>
</body>
</html>
Thymeleaf 无法解析“publishedAt,显示如下错误
Caused by: org.thymeleaf.exceptions.TemplateProcessingException:
Exception evaluating SpringEL expression: "news.publishedAt" (template: "showNews" - line 19, col 8)
at org.thymeleaf.spring5.expression.SPELVariableExpressionEvaluator.evaluate(SPELVariableExpressionEvaluator.java:290)
at org.thymeleaf.standard.expression.VariableExpression.executeVariableExpression(VariableExpression.java:166)
at org.thymeleaf.standard.expression.SimpleExpression.executeSimple(SimpleExpression.java:66)
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:109)
看起来它不适用于驼峰式字母。不知道怎么解决。
提前致谢。
【问题讨论】:
-
发布整个错误以及您的
news对象定义,以便我们查看需要更改的内容。 -
可能是拼写错误“publishedAt”而不是“publishedAt”
标签: java html spring spring-boot thymeleaf