Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc 弹簧型号-”的;模型对象不能为空";_Spring Mvc_Spring 4 - Fatal编程技术网

Spring mvc 弹簧型号-”的;模型对象不能为空";

Spring mvc 弹簧型号-”的;模型对象不能为空";,spring-mvc,spring-4,Spring Mvc,Spring 4,我的一个Spring控制器类中的一个方法 @RequestMapping(value = "/products/{productId}/specifications", method = RequestMethod.GET) public String setup(@PathVariable("productId") Integer pid, Model m) { //... m.addAttribute(foo); <-- error return "my-page";

我的一个Spring控制器类中的一个方法

@RequestMapping(value = "/products/{productId}/specifications", method = RequestMethod.GET)
public String setup(@PathVariable("productId") Integer pid, Model m) {
  //... 
  m.addAttribute(foo);  <-- error
  return "my-page";
}
@RequestMapping(value=“/products/{productId}/specifications”,method=RequestMethod.GET)
公共字符串设置(@PathVariable(“productId”)整数pid,型号m){
//... 

m、 addAttribute(foo);尽管您没有提供显示
foo
引用所指向内容的代码,但可以安全地假设它是空引用

我查看了Github上的项目代码,很清楚这里发生了什么

该方法委托给该方法,该方法使用您的问题所询问的确切消息断言所提供的
对象不为null

ModelAndView
方法:

public ModelAndView addObject(Object attributeValue) {
    getModelMap().addAttribute(attributeValue);
    return this;
}
public ModelMap addAttribute(Object attributeValue) {
    Assert.notNull(attributeValue, "Model object must not be null");
    if (attributeValue instanceof Collection && ((Collection<?>) attributeValue).isEmpty()) {
        return this;
    }
    return addAttribute(Conventions.getVariableName(attributeValue), attributeValue);
}
ModelMap
方法:

public ModelAndView addObject(Object attributeValue) {
    getModelMap().addAttribute(attributeValue);
    return this;
}
public ModelMap addAttribute(Object attributeValue) {
    Assert.notNull(attributeValue, "Model object must not be null");
    if (attributeValue instanceof Collection && ((Collection<?>) attributeValue).isEmpty()) {
        return this;
    }
    return addAttribute(Conventions.getVariableName(attributeValue), attributeValue);
}
公共模型映射addAttribute(对象属性值){ notNull(attributeValue,“模型对象不能为null”); if(集合的attributeValue实例&((集合)attributeValue.isEmpty()){ 归还这个; } 返回addAttribute(Conventions.getVariableName(attributeValue),attributeValue); }
引用的
foo
是否为空引用?您的代码片段不会显示
foo
引用指向的内容。