Preface
As a SPRINGMVC partner knows, there are two possibilities in general when we return to Page view, the two classes in this article. In fact, this article just wants to compare the roles and differences of these two classes in spring's view parsing. difference between
Personally, I think there is no difference between the two. In fact, there is a big difference between the two, specifically in the model is used to transfer data, and does not carry out business addressing. However, Modelandview is able to do business addressing, is to set the corresponding static file to request, where the static file refers to a JSP-like file. Of course, there is one of the biggest differences between the two, that is, model is every request must be carried, but Modelandview is to need our own to create new. code Example
The first is the model to pass data.
@Controller public
class Freemarkercontroller {
@SuppressWarnings (' unchecked ')
@RequestMapping (method = Requestmethod.post, value = "/freemarker") public
String GETFTL (model model) {
//construct map map Map of populated data
= new H Ashmap ();
list<testvo> Testvos = new arraylist<> ();
Testvo testvo = new Testvo ();
Testvo.setname ("Fulei");
Testvo testVo1 = new Testvo ();
Testvo1.setname ("Wangmeng");
Testvos.add (TESTVO);
Testvos.add (TESTVO1);
Map.put ("User", "Love");
Map.put ("url", "http://www.baidu.com/");
Map.put ("name", "Baidu");
Map.put ("Testvos", Testvos);
Model.addallattributes (map);
return "Test";
}
The second is Modelandview.
@RequestMapping (method = requestmethod.post, value = '/freemarker ') public
Modelandview Getftlbymodelandview () {
Modelandview Modelandview = new Modelandview ();
Construct the map map of the populated data
= new HashMap ();
list<testvo> Testvos = new arraylist<> ();
Testvo testvo = new Testvo ();
Testvo.setname ("Fulei");
Testvo testVo1 = new Testvo ();
Testvo1.setname ("Wangmeng");
Testvos.add (TESTVO);
Testvos.add (TESTVO1);
Map.put ("User", "Love");
Map.put ("url", "http://www.baidu.com/");
Map.put ("name", "Baidu");
Map.put ("Testvos", Testvos);
Modelandview.addallobjects (map);
return modelandview;
}
From the above we can see that there is a certain difference between the two, of course, the specific difference is as I described above. Summary
This blog post is mainly about the small problems of this seemingly unlikely pit, a summary of what you are doing today. If you have time, you should talk about the problems that you have encountered here.