2014-11-20 122 views
0

我收到以下异常在Spring MVC应用程序:NotReadablePropertyException:无效的属性 'MODULENAME' bean类的

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> 

春季控制器

@RequestMapping(value = "/submitSurvey", method = RequestMethod.POST) 
public String submitSurvey(@ModelAttribute("surveyModule")SurveyModule sm, Model model){ 
    surveyService.setSurveyModule(sm); 
    return "surveyHome"; 
} 

豆: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

请注意,错误说

Invalid property 'moduleName' of bean class  [java.lang.String] 

这意味着ElResolver解决surveyModule字符串而不是作为一个SurveyModule类。这意味着有相同的密钥分配,这是导致你的问题。请您使用其它型号存储键属性或会话,还要检查有没有<c:set var="surveyModule"在你的页面

+0

你是正确的地方。我纠正了它。现在一切正常。非常感谢。 – 2014-11-21 18:06:05

相关问题