將模型添加到modelandview時有什么方法可以防止StackOverflowException?
我有一個回傳模型和視圖的方法,但我已經看到,如果我嘗試將模型添加到模型視圖,它會拋出 StackOverflowException,因為模型已經有模型視圖,有沒有辦法添加它而無需先從模型中洗掉模型視圖?
((BindingAwareModelMap) model).remove("org.springframework.validation.BindingResult.modelAndView");
((BindingAwareModelMap) model).remove("modelAndView");
modelAndView.addObject(model);
return modelAndView;
uj5u.com熱心網友回復:
當您使用時ModelAndView,Spring 并不期望您手動創建一個Model.
Spring 期望您直接在內部包含的模型物件上設定您希望模型具有的屬性ModelAndView。
所以應該是
modelAndView.getModel().put("attribute1", object1);
modelAndView.getModel().put("attribute2", object2);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/414599.html
標籤:
上一篇:在資料庫中存盤Perl哈希資料
