SessionAttributes Note: By default Spring MVC data storage model to request domain. When the end of a request, the data on the failure. If you want to use across the page. We need to use the session. And @SessionAttributes annotation can make data storage model to a session in the domain.
- The annotations can only be used in class
- The annotation for temporary Map, the data ModelAndView, ModelMap Model HttpSession to or into it can be shared between a plurality of data requests (not act on the HttpServletRequest)
ModelAndView
Below, we found that the addition of this comment seems superfluous, because the handler method returns a value type is ModelAndView, which contains the view information, but also includes data information, but in fact the data mv in here is stored in the request, add the SessionAttributes comment after the property named ui data copy of
a domain into a session
Model
When Modelhandler method comprising Model parameter list, the method handler can simply return to the view, when a user makes a request, the server executes the method handler, Spring MVC automatically fill data in the Model to the request. Example UserInfoController the class code is equivalent to the following code:
Data copy above SessionAttributes notes also the model of the property named ui placed in the session domain
ModelMap&Map
When the parameter list handler method comprising org.springframework.ui.ModelMap or java.uti.Map, handler method simply returns to the view, Spring MVC ModelMap or automatically add data to the model of the Map.
Method ModelMap or put addAttribute class object can output data to the display control layer layer, and invoked through the expression EL
result
Target page as follows
Annotated class corresponding display page:
No annotated classes corresponding display page: