巴扎黑2017-04-17 17:50:31
Spring的Controller方法裡面 Model是透過方法參數注入進去的
類似於這樣:
@RequestMapping("welcome")
public String welcome(Model model) {
model.addAttribute("whatever", new SomeObject());
return "welcome";
}
如果使用ModelAndView 要這樣做
@RequestMapping("welcome")
public ModelAndView welcome() {
ModelAndView mv = new ModelAndView("welcome");
mv.addObject("whatever", new SomeObject());
return mv;
}
另外View裡不是應該這樣寫嘛
<tr>
<th th:text="#{whatever}">Name</th>
<th th:text="#{whatever}">Price</th>
</tr>
建議以後問問題 程式碼不要截圖 用文字 最好附帶完整原始碼放在git倉庫裡。