1. 程式人生 > >Spring MVC中@ModelAttribute註解

Spring MVC中@ModelAttribute註解

Spring MVC中,@ModelAttribute註解主要功能:

1、標註在引數上進行資料繫結,將前端上送的引數按照名稱繫結到指定物件中,並且將該物件自動加入ModelMap中,後續可供View層使用。

2、標註在方法上,會在每一個@RequestMapping標註的方法執行前,先執行@ModelAttribute標註的方法,如果存在多個@ModelAttribute則按順序依次執行。假如方法有返回值,則自動將返回值加入到ModelMap中。