我试图为我的项目(电话簿)制作简单的过滤器,以便能够通过他们的电子邮件而不是 id 找到用户联系人。当我简单地启动 URL 时:http://localhost:8080/home/phonebook。我收到以下错误。
错误信息
org.thymeleaf.exceptions.TemplateProcessingException:评估 SpringEL 表达式的异常:“data.content”(模板:“/home/phonebook”-第 29 行,第 13 栏)
引起:org.springframework.expression.spel.SpelEvaluationException:EL1008E:在“java.util.ArrayList”类型的对象上找不到属性或字段“内容”——可能不是公共的或无效的?
家庭控制器
@RequestMapping(value = {"/home/phonebook"}, method = RequestMethod.GET)
public String showPage(Model model, @RequestParam(defaultValue = "0") int page){
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
User user = userService.findUserByEmail(auth.getName());
model.addAttribute("data",phonebookRepository.findAllByUserEmail(user.getEmail(),PageRequest.of(page,10)));
model.addAttribute("currentPage",page);
return "/home/phonebook";
}
Run Code Online (Sandbox Code Playgroud)
电话簿.html
<tr th:each="phonebook :${data.content}">
<td th:text="${phonebook.id}"></td>
<td th:text="${phonebook.surname}"></td>
<td th:text="${phonebook.firstname}"></td>
<td th:text="${phonebook.phoneNumber}"></td>
<td>
<a th:href="@{delete/(id=${phonebook.id})}" class="btn btn-danger delBtn">Delete</a>
<a th:href="@{findOne/(id=${phonebook.id})}" class="btn btn-primary eBtn">Edit</a></td>
</tr>
</tbody>
</table>
<hr/>
<ul class="nav nav-pills">
<li class="nav-item" th:each="i: ${#numbers.sequence(0,data.totalPages-1)}">
<a …Run Code Online (Sandbox Code Playgroud)