jstl spring boot-bean属性“email”不可读或具有无效的getter方法

9q78igpj  于 2021-07-23  发布在  Java
关注(0)|答案(0)|浏览(314)

我对使用springboot和jstl相当陌生。我目前正在尝试在我的视图中实现一些东西,我可以选择多个复选框并将数据发送到我的控制器上进行操作。我想我做的每件事都是对的,但似乎找不到问题的根源。有人能帮忙吗?获取以下错误:
021-02-09 17:49:45.227错误16216---[nio-8080-exec-6]o.s.web.servlet.tags.form.checkboxtag:bean类的无效属性'email'[java.util.arraylist]:bean属性'email'不可读或具有无效的getter方法:getter的返回类型是否与setter的参数类型匹配?
org.springframework.beans.notreadablepropertyexception:bean类[java.util.arraylist]的无效属性“email”:bean属性“email”不可读或具有无效的getter方法:getter的返回类型是否与setter的参数类型匹配?位于org.springframework.beans.abstractnestablepropertyaccessor.getpropertyvalue(abstractnestablepropertyaccessor。java:625)~[ Spring Bean -5.3.3。jar:5.3.3]位于org.springframework.beans.abstractnestablepropertyaccessor.getpropertyvalue(abstractnestablepropertyaccessor。java:615)~[ Spring Bean -5.3.3。jar:5.3.3]
我的控制器:

  1. package com.bizlinks.mainapp.controller;
  2. import org.springframework.beans.factory.annotation.Autowired;
  3. import org.springframework.stereotype.Controller;
  4. import org.springframework.ui.Model;
  5. import org.springframework.web.bind.annotation.GetMapping;
  6. import org.springframework.web.bind.annotation.ModelAttribute;
  7. import org.springframework.web.bind.annotation.PostMapping;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.RequestMethod;
  10. import org.springframework.web.bind.annotation.RequestParam;
  11. import java.util.List;
  12. import com.bizlinks.mainapp.models.Lead;
  13. import com.bizlinks.mainapp.repository.UserRepository;
  14. @Controller
  15. public class AdminController {
  16. @Autowired // This means to get the bean called userRepository
  17. //Which is auto-generated by Spring, we will use it to handle the data
  18. private UserRepository userRepository;
  19. @RequestMapping(value = "admin", method = RequestMethod.GET)
  20. public String List(Model model) {
  21. List<Lead> leads = userRepository.findAll();
  22. model.addAttribute("leads", leads);
  23. return "admin";
  24. }
  25. @RequestMapping(value = "admin", method = RequestMethod.POST)
  26. public String deleteLead(@ModelAttribute("leads")List<Lead> leads){
  27. for(int i =0; i< leads.size();i++) {
  28. System.out.println(leads.get(i).getEmail());
  29. }
  30. return "admin";
  31. }
  32. }

我的型号:

  1. package com.bizlinks.mainapp.models;
  2. import javax.persistence.Column;
  3. import javax.persistence.Entity;
  4. import javax.persistence.Id;
  5. import javax.persistence.Table;
  6. @Entity
  7. @Table(name = "leads")
  8. public class Lead {
  9. @Id
  10. @Column(name = "email")
  11. private String email;
  12. @Column(name = "firstName")
  13. private String firstName;
  14. @Column(name = "surName")
  15. private String surName;
  16. @Column(name ="phone")
  17. private String phone;
  18. public void setEmail(String email) {
  19. this.email = email;
  20. }
  21. public String getEmail() {
  22. return email;
  23. }
  24. public void setFirstName(String firstName) {
  25. this.firstName = firstName;
  26. }
  27. public String getFirstName() {
  28. return firstName;
  29. }
  30. public void setSurName(String surName) {
  31. this.surName = surName;
  32. }
  33. public String getSurName() {
  34. return surName;
  35. }
  36. public void setPhone(String phone) {
  37. this.phone = phone;
  38. }
  39. public String getPhone() {
  40. return phone;
  41. }
  42. }

我的视图主体:

  1. <body>
  2. <nav class="nav nav-fill">
  3. <a class="nav-link" href="/">Home</a>
  4. </nav>
  5. <div class="container-fluid con">
  6. <table>
  7. <tr>
  8. <th>First Name</th>
  9. <th>Surname</th>
  10. <th>Email</th>
  11. <th>Phone</th>
  12. </tr>
  13. <form:form action="admin" modelAttribute="leads">
  14. <c:forEach items="${leads}" var="item">
  15. <tr>
  16. <td><c:out value="${item.email}"/></td>
  17. <td><c:out value="${item.firstName}"/></td>
  18. <td><c:out value="${item.surName}"/></td>
  19. <td><c:out value="${item.phone}"/></td>
  20. <form:checkbox path="email" value="${item.email}"/>
  21. </tr>
  22. </c:forEach>
  23. <input type="submit" value="Submit" />
  24. </form:form>
  25. </table>
  26. </div>
  27. <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
  28. <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
  29. <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.min.js"></script>
  30. </body>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题