Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Take a look on the server side code as well. You will notice that the <strong>/mapping/produces</strong> URL is mapped to a handler method in MappingController:</p> <pre><code>@RequestMapping(value="/mapping/produces", method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE) public @ResponseBody JavaBean byProducesJson() { return new JavaBean(); } </code></pre> <p>Two important things here:</p> <ul> <li>by placing the <strong>@ResponseBody</strong> annotation on the return type Spring will serialize the returned JavaBean instance directly into the HTTP response</li> <li><strong>produces=MediaType.APPLICATION_JSON_VALUE</strong> will tell Spring that JSON format should be used when serializing the returned object</li> </ul> <p>As you see this controller method just returns a new instance of the <a href="https://github.com/SpringSource/spring-mvc-showcase/blob/master/src/main/java/org/springframework/samples/mvc/mapping/JavaBean.java" rel="nofollow">JavaBean class</a> which has the following default properties:</p> <pre><code>public class JavaBean { ... private String foo = "bar"; private String fruit = "apple"; ... } </code></pre> <p>As a result you will get the mentioned <strong>{"foo":"bar","fruit":"apple"}</strong> JSON in the response.</p> <p>also from the logs you can find out which controller method was handling your request when calling a URL:</p> <pre><code>01:27:38 [tomcat-http--28] RequestMappingHandlerMapping - Looking up handler method for path /mapping/produces 01:27:38 [tomcat-http--28] RequestMappingHandlerMapping - Returning handler method [public org.springframework.samples.mvc.mapping.JavaBean org.springframework.samples.mvc.mapping.MappingController.byProducesJson()] </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload