我在Spring MVC应用程序中遇到以下异常:
org.springframework.beans.NotReadablePropertyException: Invalid property 'moduleName' of bean class [java.lang.String]: Bean property 'moduleName' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:726)
org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:717)
org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:149)
JSP代码
<form:form method="post" action="/submitSurvey" modelAttribute="surveyModule" >
<form:label path="moduleName">Module Name</form:label>
<form:input path="moduleName" />
<input type="submit" value="Save"/>
</form:form>
Spring Controller
@RequestMapping(value = "/submitSurvey", method = RequestMethod.POST)
public String submitSurvey(@ModelAttribute("surveyModule")SurveyModule sm, Model model){
surveyService.setSurveyModule(sm);
return "surveyHome";
}
Bean:SurveyModule.java
@Entity
@Table(name="SURVEYMODULE")
public class SurveyModule {
@Id
@Column(name="SurveyModuleId")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer surveyModuleId;
private String moduleName;
public Integer getSurveyModuleId() {
return surveyModuleId;
}
public void setSurveyModuleId(Integer surveyModuleId) {
this.surveyModuleId = surveyModuleId;
}
public String getModuleName() {
return moduleName;
}
public void setModuleName(String moduleName) {
this.moduleName = moduleName;
}
}
属性moduleName存在于bean类中。虽然我能够使用该属性获取数据,为什么我收到此错误?我怎么能纠正这个?
答案 0 :(得分:0)
请注意错误说明
Invalid property 'moduleName' of bean class [java.lang.String]
这意味着ElResolver将surveyModule
解析为 String ,而不是 SurveyModule 类。这意味着有一个具有相同键的赋值,这会导致您的问题。检查用于存储在其他模型属性或会话中的密钥,还检查页面中某处是否有<c:set var="surveyModule"