我創建了一個我想使用郵遞員測試的 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個贊
A Set
orHashSet
是一個java概念。Set
從 HTTP 的角度來看,沒有 a 這樣的東西,在 Postman 中也沒有 a 這樣的東西Set
。因此,從 Postman 中,您需要以invoice_ids
Spring 的解析庫可以轉換為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>
添加回答
舉報
0/150
提交
取消