數據回顯
什麼數據回顯?
提交後,如果出現錯誤,將剛纔提交的數據回顯到剛纔的提交頁面。
pojo數據回顯方法
1、springmvc默認對pojo數據進行回顯。
pojo數據傳入controller方法後,springmvc自動將pojo數據放到request域,key等於pojo類型(首字母小寫)
使用@ModelAttribute指定pojo回顯到頁面在request中的key
@RequestMapping("/editItemsSubmit") public String editItemsSubmit(Model model, @ModelAttribute("items") ItemsCustom itemsCustom ) throws Exception { return "items/editItems"; }
2、可以不用@ModelAttribute,使用最簡單方法使用 model 來回顯數據
model.addAttribute("id", id); //簡單類型回顯 model.addAttribute("items", itemsCustom); // pojo回顯