我認爲最初的問題很混亂。Spring MVC和請求屬性
我有一個HashMap,需要從我想通過Spring Controller發送到視圖的數據庫收集。我不想把這個HashMap放在model.addAttribute()中,因爲Spring Model對象返回一個Map,而我的JSP需要的集合是Collection<Object>
。如果我將我的HashMap.values()設置爲request.setAttribute,如果我的方法返回一個String,該如何去調用該請求變量到視圖?
@RequestMapping(method = RequestMethod.GET)
public String home(Locale locale, Model model, HttpServletRequest request) {
model.addAttribute("surveys", mySurveys); //this is a map and I need a Collection<Object>
//So I'd like to do this, but how do I get to the "evaluations" object in a view if I'm not dispatching it (like below)??
request.setAttribute("evaluations", mySurveys);
//RequestDispatcher rd = request.getRequestDispatcher("pathToResource");
//rd.forward(request, response);
return "home";
}
編輯:春天標籤庫不能用於這個特殊的用例。
謝謝。
您使用Spring MVC並且不能使用Spring Taglibs,它是** Spring MVC jar中的** - 爲什麼不呢? – Xaerxess
我可以使用它,但我使用的TagLib適合我們正在使用的系統的界面。用戶期望它看起來有某種特定的方式。 – Robert
因此,如果您使用addAttribute將其添加到模型中,那麼您是不是可以使用home.jsp中的$ {surveys}簡單地訪問它? – digitaljoel