Note: If the method declares annotation @responsebody, the return value is output directly to the page.
First introduced the role of Modelmap[model] and Modelandview
Modelis an interface whose implementation class is Extendedmodelmap and inherits the Modelmap class.
Modelmap
The Modelmap object is mainly used for the transfer control method to process the data to the result page, which means that we put the data needed on the result page into the Modelmap object, which is similar to the function of the setattribute method of the Request object. The data that is used to pass processing during a request. Pass parameters to the page in the following ways:
AddAttribute (String key,object value);
The data in the Modelmap can be obtained and presented on the page through a series of data presentation tags, $key or bboss, via El variable mode.
Modelmap itself cannot set the URL address alias or physical jump address of page jump, then we can set the jump URL address alias or physical jump address through the return value of the Controller method.
Modelandview
The Modelandview object has two functions:
The function one sets the turn address as follows (this is also the main difference between Modelandview and Modelmap)
Modelandview view = new Modelandview ("Path:ok");
Function Two is used for the transfer control method to process the result data to the result page, which means that we need to put the data needed on the results page into the Modelandview object, his role is similar to the request object of the SetAttribute method of action, The data that is used to pass processing during a request. Pass parameters to the page in the following ways:
AddObject (String key,object value);
The data in the Modelandview can be obtained and presented on the page through a series of data presentation tags, $key or bboss, via El variable mode.
after the introduction of the function, the following introduction to how to use
Modelmap
An instance of Modelmap is created automatically by the Bboss MVC framework and passed in as a controller method parameter, which the user does not need to create themselves.
public string Xxxxmethod (string Someparam,modelmap model) { //Omit method processing logic several //put data into the Modelmap object model, The second parameter can be any Java type model.addattribute ("key", Someparam); ...... Returns the return address return "Path:handleok";}
Modelandview
Modelandview instances are created manually by the user, which is also a difference from modelmap.
Public Modelandview Xxxxmethod (String someparam) { //omit method process logic several //build Modelandview instance and set jump address Modelandview view = new Modelandview ("Path:handleok"); Place the data in the Modelandview object view, the second parameter can be any Java type view.addobject ("key", Someparam); ...... Returns Modelandview Object view return view;}
In this bboss MVC, the role and usage of the two objects of Modelmap and Modelandview are complete
Here is the test code I wrote myself
@RequestMapping (value = "/demo", method = requestmethod.get) public Modelandview Getbusinessidlistbyip (@ Requestparam ("IP") string IP, @RequestParam ("Phoneid") string Phoneid,model Model) { Modelandview Mav = new Modelandview (); Model.addattribute ("IP", IP); Model.addattribute ("Phoneid", Phoneid); Mav.addobject (model); Mav.setviewname ("User/mav"); return MAV; } @RequestMapping (value = "/demo2", method = requestmethod.get) public Modelandview Getbusinessidlistbyip () { return new Modelandview ("User/mav", "Key", New String ("Makehappy"));
Modelandview, Model, modelmap differences in spring framework