我创建了一个我想用邮递员测试的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
}
Set
或HashSet
是一个java概念。从HTTP的角度来看,没有像Set
这样的东西,并且在Postman中没有像Set
这样的东西。所以从Postman,你需要以Spring的解析库可以转换为invoice_ids
的格式发送HashSet
。正如@Michael在评论中指出的那样,一种方法是用逗号分隔invoice_id
s:invoice_id=id1,id2,id3
。当Spring处理这个请求时,它会看到你期望HashSet
形式的数据,所以它会尝试将id1,id2,id3
转换为HashSet<Integer>
,它知道如何自动执行。
旁注:除非您特别需要HashSet
,否则使用接口而不是实现子类声明类型被认为是一种好习惯。因此,在这种情况下,我建议更改您的方法签名接受Set<Integer>
而不是HashSet<Integer>