为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕容708150 2022-10-26 15:53:02
我创建了一个我想使用邮递员测试的 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}
查看完整描述

1 回答

?
蛊毒传说

TA贡献1895条经验 获得超3个赞

SetorHashSet是一个java概念。Set从 HTTP 的角度来看,没有 a 这样的东西,在 Postman 中也没有 a 这样的东西Set。因此,从 Postman 中,您需要以invoice_idsSpring 的解析库可以转换为HashSet. 正如@Michael 在评论中指出的那样,一种方法是invoice_id像这样用逗号分隔 s: invoice_id=id1,id2,id3。当 Spring 处理此请求时,它会看到您正在期待 a 形式的数据HashSet,因此它将尝试转换id1,id2,id3为 a HashSet<Integer>,它知道如何自动执行此操作。

旁注:除非您特别需要 a HashSet,否则使用接口而不是实现子类来声明您的类型被认为是一种好习惯。因此,在这种情况下,我建议将您的方法签名更改为接受 aSet<Integer>而不是 aHashSet<Integer>


查看完整回答
反对 回复 2022-10-26
  • 1 回答
  • 0 关注
  • 91 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号