gpt4 book ai didi

java - EL1008E : Property or field 'content' cannot be found on object of type 'java.util.ArrayList' - maybe not public or not valid?

转载 作者:行者123 更新时间:2023-11-29 04:18:25 29 4
gpt4 key购买 nike

我试图为我的项目(电话簿)制作简单的过滤器,以便能够通过他们的电子邮件而不是 ID 找到用户联系人。当我简单地启动 URL 时:http://localhost:8080/home/phonebook .我收到以下错误。

错误信息

org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "data.content" (template: "/home/phonebook" - line 29, col 13)

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'content' cannot be found on object of type 'java.util.ArrayList' - maybe not public or not valid?

家庭 Controller

@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";
}

Phonebook.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 th:href="@{/home/phonebook(page=${i})}" th:text="${i}" class="nav-link"
th:classappend="${currentPage}==${i}?'active':''"></a>
</li>
</ul>

电话簿库

@Repository("phonebookRepository")
public interface PhonebookRepository extends JpaRepository<Phonebook,Integer> {
List<Phonebook> findAllByUserEmail(String email, Pageable pageable);
}

安全配置

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(dataSource)
.usersByUsernameQuery("select email, password, active from users where email=?")
.authoritiesByUsernameQuery("select u.email, r.role from users u inner join user_role ur on(u.user_id=ur.user_id) inner join role r on(ur.role_id=r.role_id) where u.email=?")
.passwordEncoder(passwordEncoder());

}

更新 1

<tr th:each="phonebook :${data}"> 进行了更改我认为它修复了它,但我遇到了一个新错误;

org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "#numbers.sequence(0,data.totalPages-1)" (template: "/home/phonebook" - line 42, col 38)

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'totalPages' cannot be found on object of type 'java.util.ArrayList' - maybe not public or not valid?

最佳答案

改变

<tr th:each="phonebook : ${data.content}">

<tr th:each="phonebook : ${data}">

因为要迭代查询列表结果,但是data.content只是一个属性。

关于java - EL1008E : Property or field 'content' cannot be found on object of type 'java.util.ArrayList' - maybe not public or not valid?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50799171/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com