SpringMVC的基礎知識整理(6)數據回顯

數據回顯
    什麼數據回顯?
        提交後,如果出現錯誤,將剛纔提交的數據回顯到剛纔的提交頁面。

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回顯

 


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章