// 大致是这样的
public class User {
private String name;
// ... get and set
}
public class Book {
// ... other fild
private User user;
// ... get and set
}
然后在表单提交的时候用
报错,
org.springframework.beans.NullValueInNestedPathException: Invalid property 'user' of bean class [com.lqz.Book]: Cannot access indexed value of property referenced in indexed property path 'user': returned null
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:547)
at org.springframework.beans.BeanWrapperImpl.getNestedBeanWrapper(BeanWrappe
原因是表单中的name的变量错了。这个值要和Controller里的@RequestParam 相对应。如果不一致的你可以用request.getParament("")取值。Spring MVC建议表单中的name值和Controller里的参数一样,这样Spring MVC会自动解析那个值的。建议你用了Spring MVC就不要学Struts2里的写法了,Spring MVC某些情况下要比Struts灵活的多!!
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。