Springboot 02_ return JSON data

Source: Internet
Author: User

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

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.