This is about the data that is queried from the database and stored in the request domain. The value can then be obtained directly from the request domain on the page.
There are 4 ways of doing this:
1): Modelandview is used as an object.
1 /**2 * The return value of the target method can be a modelandview type. 3 * It can contain view and model information4 * Springmvc will put the data in the Modelandview model into the request domain object.5 * @return6 */7@RequestMapping ("/testmodelandview")8 PublicModelandview Testmodelandview () {9String ViewName =SUCCESS;TenModelandview Modelandview =NewModelandview (viewName); One A //add model data to Modelandview. -Modelandview.addobject ("Time",NewDate ()); - the returnModelandview; -}
Get from the page:
Time: ${requestscope.time}
Both 2:model and map are passed in as parameters.
1 @RequestMapping ("/testmap")2public String testmap (map<string, Object > map) {3 4 map.put ("Names", Arrays.aslist ("Tom", "Jerry", "Mike" )); 5 return SUCCESS; 6 }
3: @ModelAttribute
/**
* 1. There are @ModelAttribute tagged methods that are called by SPRINGMVC before each target method executes!
* 2. @ModelAttribute annotations can also be used to modify the entry parameters of the POJO type of the target method, whose Value property has the following effect:
* 1). SPRINGMVC uses the Value property values to find the corresponding object in the Implicitmodel, and if it exists, it is passed directly into the parameter of the target method.
* 2). SPRINGMVC will be a value of key, the object of the POJO type is value, which is deposited into the request.
*/
@ModelAttribute
public void GetUser (@RequestParam (value= "id", required=false) Integer ID,
Map<string, object> map) {
System.out.println ("Modelattribute method");
if (id! = NULL) {
To simulate getting an object from the database
User user = new User (1, "Tom", "123456", "[email protected]", 12);
System.out.println ("Get an object from the database:" + user);
Map.put ("user", user);
}
}
SPRINGMVC processing model data (that is, data queried from the database is placed in the request domain)