`
Copperfield
  • 浏览: 254419 次
  • 性别: Icon_minigender_1
  • 来自: 上海
博客专栏
C407adc3-512e-3a03-a056-ce4607c3a3c0
java并发编程陷阱
浏览量:24592
社区版块
存档分类

springMVC中使用注解时出现嵌套对象空指针异常的解决方法

阅读更多

org.springframework.beans.NullValueInNestedPathException: Invalid property 'brand' of bean class [when.we.collide.Product]: Value of nested property 'style' is null

 

在使用annotation之前,使用springMVC提交表单之前都会执行formBackingObject(),使用注解之后,仍需要执行类似的方法,否则在绑定页面的值的时候,spring mvc根据反射得到getStyle()方法,然后invoke该方法,此时style为null,返回null,于是抛出异常,可以采用@ModelAttribute注解的方式解决:

	@ModelAttribute  
	public Product setupModelAttribute() {   
	    Product product = new Product();
	    Style style= new Style();
	    productInfo.setStyle(style);
	    return product;
	}   
	
 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics