相关疑难解决方法(0)

354
推荐指数
6
解决办法
36万
查看次数

如何以spring形式绑定子类对象提交为modelAttribute

我有

Class Shape {
      //Implementation
}
Class Round extends Shape{
      //Implementation
}
Run Code Online (Sandbox Code Playgroud)

控制器我有

@Requestmapping(value="/view/form")
public ModelAndView getForm(){
ModelAndView mav=new ModelAndView();
mav.addObject("shape",new Round());
}


@RequestMapping(value="/submit", method = RequestMethod.POST)    
public ModelAndView submitForm(@ModelAttribute("shape") Shape shape){
         if(shape instanceof Round){ //**Not giving positive result**

         }
    }
Run Code Online (Sandbox Code Playgroud)

在Jsp

<form:form action="/submit" commandName="shape" method="post">

//form tags

</form:form>
Run Code Online (Sandbox Code Playgroud)

当我用Round对象提交表单时.在控制器端,ModelAttribute没有给出Round的实例.它只给出形状的例子.这该怎么做

java spring jsp spring-mvc spring-form

6
推荐指数
1
解决办法
3121
查看次数

标签 统计

java ×2

spring-mvc ×2

jsp ×1

modelattribute ×1

spring ×1

spring-form ×1