我在Spring/Hibernate应用程序中有一个模型类层次结构。抽象类和Spring MVC @ ModelAttribute/@ RequestParam
当向Spring MVC控制器提交POST表单时,是否有任何指定被提交对象类型的标准方式,所以Spring可以实例化在接收方法的@ModelAttribute或@RequestParam中声明的类型的正确子类?
例如:
public abstract class Product {...}
public class Album extends Product {...}
public class Single extends Product {...}
//Meanwhile, in the controller...
@RequestMapping("/submit.html")
public ModelAndView addProduct(@ModelAttribute("product") @Valid Product product, BindingResult bindingResult, Model model)
{
...//Do stuff, and get either an Album or Single
}
杰克逊可以反序列化JSON作为使用@JsonTypeInfo注释的亚型特异性。我希望Spring能做同样的事情。
谢谢你,我的意思是这是可能的,当_not_提交JSON有效载荷,而普通帖子的形式提交。 –
@Deejay确定更新了我的答案 –
嗨,我尝试解决类似的问题,但没有结果..这我我的问题:http://stackoverflow.com/questions/21550238/how-instantiate-a-concrete-class- in-init-binder可以帮助我吗? – Teo