如果我定义两个相同类的bean而不给出任何范围.然后将创建多少个类实例.例如
在applicationContext.xml中
<bean name="testBean" class="com.test.Example"/>
<bean name="myBean" class="com.test.Example"/>
Run Code Online (Sandbox Code Playgroud) 我有
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的实例.它只给出形状的例子.这该怎么做