javascript - SpringMVC return value encapsulation problem
过去多啦不再A梦
过去多啦不再A梦 2017-05-27 17:40:12
0
3
912

During the learning process, the return value of SSM is usually the name of the jsp page, and then returned directly to this page
When encountering AJAX JSON at work, the data will be encapsulated and returned to the page! As shown in the picture

Excuse me, what is the significance of such encapsulation? Is it because the value transfer speed is faster, or is there some other reason?

过去多啦不再A梦
过去多啦不再A梦

reply all(3)
淡淡烟草味

The meaning is that spring will help you serialize it into json

習慣沉默

SpringMvc jump page and return object method:

    //跳转到jsp页面
    @RequestMapping("jspViewTest")
    public String jspViewTest() {
        return "index";
    }

    //返回数据对象
    @RequestMapping("dataTest")
    @ResponseBody//使用该注解返回值会转成json格式,而不是进行页面跳转
    public String dataTest() {
        return "index";
    }

As for the encapsulated object you mentioned, I think it’s because:
It encapsulates a unified return object. All interfaces provided by the backend return the same object. After receiving the object returned by the backend, the front end only needs to follow the format of this unified object. It will be more convenient to analyze it, and it will also facilitate the separation of the front and back ends.

伊谢尔伦

The usual encapsulated fields of the Result object are: code, msg, data

code represents the return code, for example, 1000 represents success, 1001 represents parameter error, 1002 represents format error, etc.
msg represents the returned information. Information does not necessarily have to be an error, so it can be more versatile.
data represents the returned data

This is the most common package. The author can refer to it to see if it needs improvement

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template