org.springframework.beans.NotReadablePropertyException

时间:2019-01-03 22:46:29

标签: spring spring-boot spring-mvc

在我的Web应用程序中,我想构建一个注册表单,其中希望列出可以编辑和保存的用户联系信息的所有属性。但是,当我运行代码时,出现以下错误。 当我是新手并且正在学习时,任何帮助将不胜感激。

2019-01-03 17:09:58.705 ERROR 12223 --- [nio-8080-exec-5] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [An exception occurred processing JSP page /WEB-INF/views/enrollment/view.jsp at line 382
org.springframework.beans.NotReadablePropertyException: Invalid property 'contact' of bean class [com.intelo.model.Enrollment]: Bean property 'contact' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

这是我的view.jsp

<form:form id="editRegistration" action="/enrollment/action" modelAttribute="enrollment" method="post" enctype="multipart/form-data">
            <input type="hidden" name="enrollmentId" value="${enrollment.id}">

...

<c:forEach items="${contacts}" var="contact">

                                            <div class="form-group col-md-6">
                                                <label class="control-label">First Name</label>
                                                <form:input class="form-control" path="contact.firstName" disabled="${allowedActions.edit? 'false' : 'true'}"/>
                                            </div>


                                        </c:forEach>

这是我的EnrollmentControleller:

@GetMapping("/enrollment/view") 
public String viewEnrollment(@ModelAttribute("enrollment") Enrollment enrollment, Model model,
    @ModelAttribute("user") Member user) 
{

    StateManager stateManager = StateManager.getStateManager(enrollment);
    model.addAttribute("hasActions", stateManager.allowedActions(user).size() > 0);
    model.addAttribute("allowedActions", stateManager.allowedActionMap(user));
    model.addAttribute("isAdministrator", stateManager.getRoleInContext(user).hasAdministratorPrivilege());

    model.addAttribute("pageTitle", "View Enrollment");

    RegistrationDetails registrationDetails = enrollment.getRegistrationDetails();
    model.addAttribute("studentInformation", registrationDetails.getStudentInformation());
    model.addAttribute("healthInformation", registrationDetails.getHealthInformation());
    model.addAttribute("emergencyContact", registrationDetails.getEmergencyContact());
    model.addAttribute("familyInformation", registrationDetails.getFamilyInformation());
    model.addAttribute("schoolHistory", registrationDetails.getSchoolHistory());
    model.addAttribute("contacts", registrationDetails.getContacts());
    model.addAttribute("siblings", registrationDetails.getSiblings());
    model.addAttribute("preferredSite", registrationDetails.getPreferredSite());

    return "enrollment/view";
}

注册课程:

@Entity
@Table(name="enrollments")
@OnDelete(action = OnDeleteAction.CASCADE)
public class Enrollment extends ModelObject {

    @JsonProperty("firstName")
    private String firstName = "";
    @JsonProperty("middleName")
    private String middleName = "";
    @JsonProperty("lastName")
    private String lastName = "";

    @JsonProperty("birthDate")
    @DateTimeFormat(pattern="MM/dd/uuuu")
    private LocalDate birthDate = LocalDate.now();

    @JsonProperty("studentGrade")
    private String studentGrade = null;

    @JsonProperty("registrationDate")
    @JsonDeserialize(using = LocalDateDeserializer.class)  
    @JsonSerialize(using = LocalDateSerializer.class)  
    @DateTimeFormat(pattern="MM/dd/uuuu")
    private LocalDate registrationDate = LocalDate.now();

    @JsonIgnore
    @OneToOne(fetch=FetchType.LAZY, mappedBy="enrollment", cascade={CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE}, orphanRemoval=true)
    @OnDelete(action = OnDeleteAction.CASCADE)
    RegistrationDetails registrationDetails = null;

    @JsonIgnore
    @ManyToOne
    @JoinColumn(name = "programId")
    private Program program = null;

    @JsonIgnore
    @OrderBy("date")
    @OneToMany (mappedBy = "enrollment", cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE})
    @OnDelete(action = OnDeleteAction.CASCADE)
    private List<AttendanceRecord> attendanceRecords = new ArrayList<AttendanceRecord>();

    public Enrollment() {
        super();

        setType(this.getClass().getCanonicalName());
        setState(State.DRAFT);

        setRegistrationDetails(new RegistrationDetails());
    }

    public String getStudentGrade() {
        return studentGrade;
    }

    public void setStudentGrade(String studentGrade) {
        this.studentGrade = studentGrade;
    }

    public List<AttendanceRecord> getAttendance() {
        return attendanceRecords;
    }

    public void addAttendanceRecord(AttendanceRecord attendanceRecord) {
        attendanceRecords.add(attendanceRecord);
        attendanceRecord.setEnrollment(this);
    }

    public void removeAttendanceRecord(AttendanceRecord attendanceRecord) {
        attendanceRecords.remove(attendanceRecord);
        attendanceRecord.setEnrollment(null);
    }

     public LocalDate getRegistrationDate() {
        return registrationDate;
    }

    public void setRegistrationDate(LocalDate registrationDate) {
        this.registrationDate = registrationDate;
    }

    public Program getProgram() {
        return program;
    }

    public void setProgram(Program program) {
        this.program = program;
        setParent(program);
    }

    @Override
    public ParentContext getParentContext() {
        return program;
    }

    public RegistrationDetails getRegistrationDetails() {
        return registrationDetails;
    }

    public void setRegistrationDetails(RegistrationDetails registrationDetails) {
        if (this.registrationDetails != null)
            registrationDetails.setEnrollment(null);

        this.registrationDetails = registrationDetails;
        registrationDetails.setEnrollment(this);
    }

    public String getFirstName() {
        return firstName;
    }

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

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getMiddleName() {
        return middleName;
    }

    public void setMiddleName(String middleName) {
        this.middleName = middleName;
    }

    public LocalDate getBirthDate() {
        return birthDate;
    }

    public void setBirthDate(LocalDate birthDate) {
        this.birthDate = birthDate;
    }
}

这是我的联系方式

@Embeddable
public class Contact {
    String firstName = "";
    String lastName = "";
    String email = "";
    String homePhone = "";
    String dayPhone = "";
    String cellPhone = "";
    String relationship = "";

    @Embedded
    @AttributeOverrides({
        @AttributeOverride(name="street", column=@Column(name="contact_street")),
        @AttributeOverride(name="apartment", column=@Column(name="contact_apartment")),
        @AttributeOverride(name="city", column=@Column(name="contact_city")),
        @AttributeOverride(name="state", column=@Column(name="contact_state")),
        @AttributeOverride(name="zipCode", column=@Column(name="contact_zipcode")),
        @AttributeOverride(name="country", column=@Column(name="contact_country"))
    })
    Address address = new Address();

    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public String getHomePhone() {
        return homePhone;
    }
    public void setHomePhone(String homePhone) {
        this.homePhone = homePhone;
    }
    public String getDayPhone() {
        return dayPhone;
    }
    public void setDayPhone(String dayPhone) {
        this.dayPhone = dayPhone;
    }
    public String getCellPhone() {
        return cellPhone;
    }
    public void setCellPhone(String cellPhone) {
        this.cellPhone = cellPhone;
    }
    public String getRelationship() {
        return relationship;
    }
    public void setRelationship(String relationship) {
        this.relationship = relationship;
    }
    public Address getAddress() {
        return address;
    }

}

0 个答案:

没有答案