如何将 HashSet 传递给服务器以测试邮递员的 API?

我创建了一个我想使用邮递员测试的 API。我的 api 接受许多参数,其中一个参数是 HashSet。我不知道如何使用邮递员传递 HashSet 参数。请帮我。提前致谢


这是我的代码:


@PutMapping

    @ApiOperation(value = "collectMultiInvoices", nickname = "collectMultiInvoices")

    public BaseResponse collectAmountMultipleInvoices(@RequestParam(value = "invoice_id") HashSet<Integer> invoiceIds,

                                      @RequestParam("date") String _date,

                                      @RequestParam(value = "cash", required = false) Float cashAmount,

                                      @RequestParam(value = "chequeAmount", required = false) Float chequeAmount,

                                      @RequestParam(value = "chequeNumber", required = false) String chequeNumber,

                                      @RequestParam(value = "chequeDate", required = false) String _chequeDate,

                                      @RequestParam(value = "chequeImage", required = false) MultipartFile chequeImage,

                                      @RequestParam(value = "chequeBankName", required = false) String chequeBankName,

                                      @RequestParam(value = "chequeBankBranch", required = false) String chequeBankBranch,

                                      @RequestParam(value = "otherPaymentAmount", required = false) Float otherPaymentAmount,

                                      @RequestParam(value = "otherPaymentType", required = false) Integer otherPaymentType,

                                      @RequestParam(value = "otherPaymentTransactionId", required = false) String otherPaymentTransactionId,

                                      @RequestParam(value = "discountPercentorAmount", required = false) String discountPercentorAmount,

                                      @RequestParam(value = "discountId", required = false) String discountId) throws AppException.RequestFieldError, AppException.CollectionAmountMoreThanOutstanding {



//method implementation


}


慕容708150
浏览 92回答 1
1回答

蛊毒传说

A&nbsp;SetorHashSet是一个java概念。Set从 HTTP 的角度来看,没有 a 这样的东西,在 Postman 中也没有 a 这样的东西Set。因此,从 Postman 中,您需要以invoice_idsSpring 的解析库可以转换为HashSet.&nbsp;正如@Michael 在评论中指出的那样,一种方法是invoice_id像这样用逗号分隔 s:&nbsp;invoice_id=id1,id2,id3。当 Spring 处理此请求时,它会看到您正在期待 a 形式的数据HashSet,因此它将尝试转换id1,id2,id3为 a&nbsp;HashSet<Integer>,它知道如何自动执行此操作。旁注:除非您特别需要 a&nbsp;HashSet,否则使用接口而不是实现子类来声明您的类型被认为是一种好习惯。因此,在这种情况下,我建议将您的方法签名更改为接受 aSet<Integer>而不是 aHashSet<Integer>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java