[英]Java Spring adding model to ModelAndView throws StackOverflowException
Is there any way to prevent StackOverflowException when adding model into modelandview?将 model 添加到 modelandview 时,有什么方法可以防止 StackOverflowException?
I have a method that returns a modelandview but I've seen that if I try to add model to modelandview it throws and StackOverflowException because Model already has modelandview, is there any way to add it without need to remove modelandview from model first? I have a method that returns a modelandview but I've seen that if I try to add model to modelandview it throws and StackOverflowException because Model already has modelandview, is there any way to add it without need to remove modelandview from model first?
((BindingAwareModelMap) model).remove("org.springframework.validation.BindingResult.modelAndView");
((BindingAwareModelMap) model).remove("modelAndView");
modelAndView.addObject(model);
return modelAndView;
When you use ModelAndView
, Spring does not expect you to manually create a Model
.当您使用ModelAndView
时, Spring 不希望您手动创建Model
。
Spring expects that you set the attributes that you want for model to have directly on the model object contained inside ModelAndView
. Spring 希望您将 model 的属性设置为直接在 model ModelAndView
中包含的模型中。
So it should be所以应该是
modelAndView.getModel().put("attribute1", object1);
modelAndView.getModel().put("attribute2", object2);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.