Spring MVC Rest return value is empty

Source: Internet
Author: User
Tags getmessage

Problem Description:

With spring Restful, you can correctly access the background through the URL of the browser's address bar and do not report errors, but the front desk always gets no data, the front desk also received a response from the background, that is, no data.

specific as follows:

using Spring Restful for different formats, you can send different formatted data, such as JSON, XML, HTML .....

For the configuration file, the following:

Refer to Spring MVC Rest learning one: http://my.oschina.net/heweipo/blog/337581

Reference Spring MVC Rest Learning II: http://my.oschina.net/heweipo/blog/340040

for the Controller interface, start with the following declaration:

@RequestMapping ("/getmessage") public String getMessage (httpservletrequest request, httpservletresponse response, Mod            Elmap model) {model.put ("message", New Message ());    return null; }

request in Browser, Http:ip:port/server/uri/getmessage.json

The result: This method can be accessed, because I tried with a breakpoint, but the return value is empty, the original result should be to return a JSON-formatted message content, but not satisfactory. The specific reason is not very clear, but the following modifications have been made to solve the problem:

@RequestMapping ("/getmessage") public String getMessage (httpservletrequest request, Modelmap model) {Model.put ("            Message ", new Message ());    return null; }

Summary:

Before and after the interface contrast, found that is more than a httpservletresponse response parameters, the results are passable, but the problem finally solved.

In addition I did not use @responsbody test, theoretically, should also be possible.


Spring MVC Rest return value is empty

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.