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

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

我对使用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]
我的控制器:

package com.bizlinks.mainapp.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;

import com.bizlinks.mainapp.models.Lead;
import com.bizlinks.mainapp.repository.UserRepository;

@Controller
public class AdminController {

    @Autowired // This means to get the bean called userRepository
    //Which is auto-generated by Spring, we will use it to handle the data
    private UserRepository userRepository;  

    @RequestMapping(value = "admin", method = RequestMethod.GET)
    public String List(Model model) {

        List<Lead> leads = userRepository.findAll();
        model.addAttribute("leads", leads);

        return "admin";

    }

    @RequestMapping(value = "admin", method = RequestMethod.POST)
    public String deleteLead(@ModelAttribute("leads")List<Lead> leads){

        for(int i =0; i< leads.size();i++) {

            System.out.println(leads.get(i).getEmail());
        }

        return "admin";
    }
}

我的型号:

package com.bizlinks.mainapp.models;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "leads")
public class Lead {

    @Id
    @Column(name = "email")
    private String email;

    @Column(name = "firstName")
    private String firstName;

    @Column(name = "surName")
    private String surName;

    @Column(name ="phone")
    private String phone;

    public void setEmail(String email) {
        this.email = email;
    }

    public String getEmail() {
        return email;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setSurName(String surName) {
        this.surName = surName;
    }

    public String getSurName() {
        return surName;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }
    public String getPhone() {
        return phone;
    }
}

我的视图主体:

<body>

    <nav class="nav nav-fill">

      <a class="nav-link" href="/">Home</a>

    </nav>

    <div class="container-fluid con">
            <table>
                    <tr>
                        <th>First Name</th>
                        <th>Surname</th>
                        <th>Email</th>
                        <th>Phone</th>
                    </tr>

                  <form:form action="admin" modelAttribute="leads">
                     <c:forEach items="${leads}" var="item">                    
                        <tr>

                            <td><c:out value="${item.email}"/></td>                     
                            <td><c:out value="${item.firstName}"/></td>
                            <td><c:out value="${item.surName}"/></td>                       
                            <td><c:out value="${item.phone}"/></td>
                            <form:checkbox path="email" value="${item.email}"/> 

                        </tr>                     
                   </c:forEach>

                   <input type="submit" value="Submit" /> 

                  </form:form>

            </table>
    </div>

        <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.min.js"></script>
</body>

暂无答案!

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

相关问题