When developing an API in a restful way, you need to return data in JSON format.
But what's the most convenient?
1. SPRINGMVC Collection Com.fastxml.jackson.core The following three package Jackson-core,jackson-databind, jackson-annotions configured in the Pom.xml file,
2. Use the @responsebody annotation function inside the @controll class
3. Adding <mvc:annotion-driven/> to the spring configuration file, this configuration is important, the key to SPRINGMVC's ability to work, and the key to being able to match Jackson's return JSON format.
Then start the service and you'll see the results in JSON format.
Why use Jackson to look at the source code:
When the @response annotation is parsed and executed, it defaults to the Mappingjackson2httpmessageconverter class, which inherits Abstracthttpmessageconverter. This class refers to the various classes within Jackson. So to introduce the Jackson bag to use.
Import com.fasterxml.jackson.core.JsonEncoding;
Import Com.fasterxml.jackson.core.JsonGenerator;
Import com.fasterxml.jackson.core.JsonProcessingException;
Import Com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
Import Com.fasterxml.jackson.databind.JavaType;
Import Com.fasterxml.jackson.databind.ObjectMapper;
Import Com.fasterxml.jackson.databind.SerializationFeature;
SPRINGMVC return JSON format