代码之家  ›  专栏  ›  技术社区  ›  pixel

Springboot-如何命名JSON响应中的响应数组和对象

  •  0
  • pixel  · 技术社区  · 4 年前

    @GetMapping()
    public List<CarResponse> getCars() {
        List<CarResponse> cars= carService.getCars();
        return cars;
    }
    

    我的CarResponse看起来像:

    public class CarResponse {
        private int id;
        private String type;
        private String model;
    }
    

    [
        {
            "id": 1,
            "type": "SUV",
            "model": "Toyota"
        },
        {
            "id": 2,
            "type": "SPORT",
            "model": "Porsche"
        },
        ...
    ]
    

    {
        "cars": [
                "car": {
                    "id": 1,
                    "type": "SUV",
                    "model": "Toyota"
                },
                "car": {
                    "id": 2,
                    "type": "SPORT",
                    "model": "Porsche"
                },
                ...
        ]
    }
    
    0 回复  |  直到 4 年前