小编ssm*_*ssm的帖子

在单个应用程序上下文中定义两个相同类的bean

如果我定义两个相同类的bean而不给出任何范围.然后将创建多少个类实例.例如

在applicationContext.xml中

<bean name="testBean" class="com.test.Example"/>
<bean name="myBean" class="com.test.Example"/>
Run Code Online (Sandbox Code Playgroud)

spring spring-mvc

16
推荐指数
1
解决办法
4万
查看次数

如何以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
查看次数

标签 统计

spring ×2

spring-mvc ×2

java ×1

jsp ×1

spring-form ×1