Spring boot 对Spring Boot和Thymeleaf使用分页时出错
我有以下一些代码来对控制器发送的数据进行分页:Spring boot 对Spring Boot和Thymeleaf使用分页时出错,spring-boot,pagination,thymeleaf,Spring Boot,Pagination,Thymeleaf,我有以下一些代码来对控制器发送的数据进行分页: <div class="col-xs-12 col-md-6"> <ul class="list-group"> <li class="list-group-item" th:each="history:${batchExecuteHistory}" th:if="${history.status == true}">
<div class="col-xs-12 col-md-6">
<ul class="list-group">
<li class="list-group-item" th:each="history:${batchExecuteHistory}"
th:if="${history.status == true}">
<button type="button" class="btn btn-success">Success</button>
<span th:text="${history.timeEnd}"></span>
<span th:text="${history.rowInput}"></span>
</li>
<li class="list-group-item" th:each="history:${batchExecuteHistory}"
th:if="${history.status == false}">
<button type="button" class="btn btn-danger">Danger</button>
<span th:text="${history.timeEnd}"></span>
<span th:text="${history.errorContent}"></span>
</li>
</ul>
<ul class="pagination">
<li th:each='i : ${#numbers.sequence(0, nubmerOfPage.totalPages-1)}'
th:class="(${i}==${pnubmerOfPage.number})? 'active' : ''"
style="display: inline"><span th:if='${i}==${nubmerOfPage.number}'
th:text='${i+1}'>1</span> <a th:if='${i}!=${nubmerOfPage.number}'
th:href="@{${url}(nubmerOfPage=${i})}"> <span th:text='${i+1}'>1</span></a>
</li>
</ul>
</div>
-
成功
-
危险
- 1
我犯了这样一个错误:
org.thymeleaf.exceptions.TemplateProcessingException:异常评估SpringEL表达式:“#numbers.sequence(0,numerofpage.totalPages-1)”
控制器中的代码:
Page<BatchExecuteHistory> batchExecuteHistory =
batchExecuteHistoryService.getBatchExecuteHistory(id, pageable);
model.addAttribute("jobDetailModel", jobDetailModel);
model.addAttribute("batchExecuteHistory", batchExecuteHistory);
model.addAttribute("nubmerOfPage", batchExecuteHistory.getContent());
model.addAttribute("url", "/jobManagementDetail/{id}/{name}/{time}");
Page batchExecuteHistory=
getBatchExecuteHistory(id,可分页);
addAttribute(“jobDetailModel”,jobDetailModel);
addAttribute(“batchExecuteHistory”,batchExecuteHistory);
addAttribute(“numberofpage”,batchExecuteHistory.getContent());
addAttribute(“url”,“/jobManagementDetail/{id}/{name}/{time}”);
我找到了根本问题:
org.springframework.expression.spel.SpelEvaluationException:EL1008E:在类型为“java.util.Collections$UnmodifiableRandomAccessList”的对象上找不到属性或字段“totalPages”—可能不是公共的
我在此链接中使用代码:
有人知道为什么吗?请帮助在您提供的教程中,它说您必须像这样使用控制器:
@RequestMapping(value="/word/wordList", method=RequestMethod.GET)
public String getWordList(Model model, Pageable pageable) {
Page<Word> wordPage = wordService.getAllWord(pageable);
PageWrapper<Word> page = new PageWrapper<Word>(wordPage, "/word/wordList");
model.addAttribute("page", page); //HERE
model.addAttribute("words", page.getContent());
return "/word/wordList";
}
因此,将其设置为应该可以解决此问题:
model.addAttribute("nubmerOfPage", batchExecuteHistory);
我修复了这个问题,但仍然没有任何帮助:(我发现页面有一个类似getTotalPage的方法:(我尝试了numberOfPage.totalPages或numberOfPage.getTotalPages(),但它不起作用
model.addAttribute("nubmerOfPage", batchExecuteHistory);