search

Home  >  Q&A  >  body text

javascript - SpringMVC return value encapsulation problem

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梦2787 days ago952

reply all(3)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-05-27 17:42:12

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

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-27 17:42:12

    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.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-27 17:42:12

    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

    reply
    0
  • Cancelreply