because of an existing model object of the same name

背景:java

  視圖解析器(咱們用的是velocity) spring

報錯:session

  because of an existing model object of the same nameide

按照網上給的緣由 :blog

設置了屬性exposeSessionAttributes爲true以後,全部的session中的變量都會在傳給視圖(velocity模板)時被合併到model中。這時若是在控制器中使用了@sessionAttributes註解(會把session中指定的變量存到model中),在最後合併model的時候會報Cannot expose session attribute 'xxx' because of an existing model object of the same name異常。查看了AbstractTemplateView.java文件後,發現spring在合併的時候還判斷了allowSessionOverride這個屬性,若是爲false,就會拋出上面提到的異常。因此這種狀況下,還要在配置文件的viewResolver中添加allowSessionOverride屬性,value爲true,這樣即便遇到重複的值,也會直接使用Map中的put方法將舊值覆蓋。ci

 

發現並不行 ,最後源代碼斷點看了下it

 

 OK  那麼久是須要配置下這個判斷條件io

 解決了模板

相關文章
相關標籤/搜索