1 回答

largeQ
TA貢獻2039條經驗 獲得超8個贊
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倉庫里。
添加回答
舉報
0/150
提交
取消