![](/img/trans.png)
[英](Java) Access Spring Model without using parameters or ModelAndView
[英]Java Spring adding model to ModelAndView throws StackOverflowException
将 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?
((BindingAwareModelMap) model).remove("org.springframework.validation.BindingResult.modelAndView");
((BindingAwareModelMap) model).remove("modelAndView");
modelAndView.addObject(model);
return modelAndView;
当您使用ModelAndView
时, Spring 不希望您手动创建Model
。
Spring 希望您将 model 的属性设置为直接在 model ModelAndView
中包含的模型中。
所以应该是
modelAndView.getModel().put("attribute1", object1);
modelAndView.getModel().put("attribute2", object2);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.