SpringMVC annotations

Disclaimer: The materials used in this column are written by VIP students of Kaige Academy. Students have the right to remain anonymous and have the right to final interpretation of the article. Kaige Academy aims to promote VIP students to learn from each other based on public notes.

SpringMVC annotations

@ModelAndView (business return parameter)
wraps the object data by adding objects to it, just like adding Attributes, and then returns to the specified place by return.
Function:
1. Set the jump page
2. Bring parameters to the page, which is equivalent to adding to the request

image

image

@Model&Map (with value)
MVC will automatically store the data in your Model or the key value of the Map in the request by default. Function:
We can add our data to it through this object, which is equivalent to adding it to the request, and then we can get the object parameters through the request.

image

image

image

@SessionAttributes
retrieves whether the data of Model and Map exists in the session object.
Names&Value is used to retrieve the keys in Model and Map.
Types is used to retrieve
the annotations added to our action, in which names/value or type can be added, which means that any key value in Model and Map has names in it. If the object types in Model and Map have the type specified in Types, they will also be stored in the session, so that requests and sessions both store the same data.

In the page, you can get the value stored in the session object through sessionScope.name.

image

image

image

image

@SessionAttribute
plus this annotation means to help me get a value in the session
Name/value means the name
@RequestAttribut
plus this annotation means to help me get a value in the request

image

image

ModelAttribute

Execute methods ahead of time, before any methods in your action are executed

usage:

1. The method can accept any parameters, such as Model, Map, String...

2. If you want to get the data loaded in advance in other business methods, you can add the @ModelAttribute annotation before the parameter. Adding a string to it is easy to distinguish whether the name of the retrieved data is consistent. arrived.

image

image

image

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325389968&siteId=291194637