【发布时间】:2020-06-10 03:29:24
【问题描述】:
我一直在为我的应用开发一个灵活的分页解决方案,这里是片段代码:
<div th:fragment="pagination(form, postUrl)">
<nav aria-label="Page Navigation">
<ul class="pagination justify-content-center">
<li class="page-item"
th:classappend="${form?.page == 1} ? disabled : ''">
<form th:action="@{${postUrl}}" th:object="${__${form}__}"
method="post">
<input hidden th:field="${form?.page}" th:value="${form?.page} - 1" />
<button class="page-link" th:text="#{page.previous}" />
</form>
</li>
<div
th:with="pageLimit=${form?.totalPages > 0} ? ${form?.totalPages} : 1">
<li class="page-item"
th:each="i : ${#numbers.sequence(1, pageLimit)}">
<form th:action="@{${postUrl}}" th:object="${__${form}__}"
method="post">
<input hidden th:field="*{page}" th:value="${i}" />
<button class="page-link" style="border-radius: 0px"
th:text="${i}" />
</form>
</li>
</div>
<li class="page-item">
<form th:action="@{${postUrl}}" th:object="${__${form}__}"
method="post">
<input hidden th:field="*{page}" th:value="${form?.page} + 1" />
<button class="page-link" th:text="#{page.next}" />
</form>
</li>
</ul>
</nav>
</div>
片段变量是这样传入的:
<div
th:replace="fragments/pagination :: pagination(${objectForm}, '/my/url-is-here')">
但是,在处理视图时,我收到此错误(为清楚起见而缩短):
Exception evaluating SpringEL expression: "my.object.ObjectForm@66bc4dd8" (template: "fragments/pagination" - line 6, col 37)
...
org.springframework.expression.spel.SpelParseException: EL1041E: After parsing a valid expression, there is still more data in the expression: 'bean_ref(@)'
这肯定是 bean 预处理有问题,因为如果我按原样使用没有片段的代码,__${form}__ 或 th:with 变量,它就可以了。那么有人知道这里发生了什么吗?
任何见解将不胜感激!
【问题讨论】:
-
我有完全相同的错误。我通过切换到 th:name / th:value 暂时解决了。 th:name 可能被误用,例如列表如下: th:name="${'listInForm[' + ${i.index} + '].attributeName'}" 不好,但工作
-
我想我暂时也可以解决这个问题,但我仍然想找到错误的根源。谢谢!
标签: html spring thymeleaf spring-el