The difference between Springmvc-model and Modelandview __spring

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.