On the basis of Springboot 01_helloworld to return JSON data, now the front and back end of the case is separated by the majority of JSON to interact with, the following to take advantage of Springboot return JSON format data.
1: New Pesron.java
@Data Public class Person { // number private String ID; // name Private String name; // Sex Private String Gender;}
For @data annotations, refer to the Lombok tutorial.
2: New Jsoncontroller.java
@RestController @requestmapping ("/json") Public class Jsoncontroller { @GetMapping ("/person/{id}") public person Returnpersonjson (@PathVariable String id) { new person (); Person.setid (ID); Person.setname ("Jim"); Person.setgender ("female"); return Person ; }}
3: Startup Project, visit: LOCALHOST:8080/JSON/PERSON/1
If you return the following, congratulations on the successful return of the data in JSON format.
Note
Here is the default JSON framework for Springboot, or you can customize the JSON framework, such as the Fastjson framework for serializing objects, as described in the next article: Springboot 03_ uses Fastjson to return JSON data.
Springboot 02_ return JSON data