How Spring MVC puts objects into the model
This article shares with you about how Spring MVC puts objects into the model. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Put objects into the model
In the application of the MVC architecture, the controller inputs data into the model, which is used in the view. As you can see from the example in the previous section, the addObject () of the ModelAndView class is used to put objects into the model in the form of name-value pairs:
ModelView.addObject ("listUser", listUser); modelView.addObject ("siteName", newString ("CodeJava.net")); modelView.addObject ("users", 1200000)
Spring also supports declaring Map type parameters in processor methods. Spring uses this mapping to store objects that will be put into the model. Such as:
@ RequestMapping (method = RequestMethod.GET) publicStringviewStats (Map model) {model.put ("siteName", "CodeJava.net"); model.put ("pageviews", 320000); return "Stats";}
This approach is simpler than using the ModelAndView object. Spring allows users to choose Map objects and ModelAndView objects flexibly.
Thank you for reading! This is the end of the article on "how Spring MVC puts objects into the model". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!