【问题标题】:How to design post api which accepts JSON Array as input in springboot?如何设计在spring boot中接受JSON数组作为输入的post api?
【发布时间】:2020-08-04 17:44:46
【问题描述】:

输入json

[{"customerId":"1","customerName":"a"}, {"customerId":"2","customerName":"b"}]

【问题讨论】:

    标签: spring-boot rest validation http-post


    【解决方案1】:

    您需要以适当的方式为参数定义请求--

    .

    1. 方法的签名可以是--
    postCustomers(Customers customers)
    

    .

    1. Customers 可以定义为 --
    public class Customers {
        @JsonProperty("customers")
        private List<Customer> customers;
    }
    

    .

    1. 个人Customer 可以基于所需的属性进行建模--
    public class Customer {
        @JsonProperty("customerId")
        private String customerId;
    
        @JsonProperty("customerName")
        private String customerName;
    }
    

    【讨论】:

      猜你喜欢
      • 2022-08-20
      • 2017-11-25
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 2015-12-07
      • 1970-01-01
      相关资源
      最近更新 更多