Why do most programs use Model.addattribute () instead of Httpserveletrequest.setattribute () when passing a value to a JSP in a controller?
In fact, the model data, the final spring is also written to the HttpServletRequest attribute, just use model more in line with the MVC design, reduce the inter-layer coupling.
@RequestMapping (value= "/list", method=requestmethod.get) PublicString list (model model) {//the foreground output must be in the form of a ${ul.value. Property name}Model.addattribute ("UserList", userlist); return"User/userlist"; } @RequestMapping (Value= "/userlist", method=requestmethod.get) PublicString list (HttpServletRequest request) {//the foreground output must be in the form of a shape like ${user.id}List<user> userlist =NewArraylist<user>(); Userlist.add (NewUser ("1", "YONGHU1", "121", "[email protected]")); Userlist.add (NewUser ("2", "Yonghu2", "122", "[email protected]")); Userlist.add (NewUser ("3", "Yonghu3", "123", "[email protected]")); Request.setattribute ("UserList", userlist); return"User/userlist"; }
Java SPRINGMVC Framework Learning (ii) differences between httpserveltrequest and model values