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?
The meaning is that spring will help you serialize it into json
SpringMvc jump page and return object method:
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