我創(chuàng)建了一個(gè)我想使用郵遞員測試的 API。我的 api 接受許多參數(shù),其中一個(gè)參數(shù)是 HashSet。我不知道如何使用郵遞員傳遞 HashSet 參數(shù)。請(qǐng)幫我。提前致謝這是我的代碼:@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貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超3個(gè)贊
A Set
orHashSet
是一個(gè)java概念。Set
從 HTTP 的角度來看,沒有 a 這樣的東西,在 Postman 中也沒有 a 這樣的東西Set
。因此,從 Postman 中,您需要以invoice_ids
Spring 的解析庫可以轉(zhuǎn)換為HashSet
. 正如@Michael 在評(píng)論中指出的那樣,一種方法是invoice_id
像這樣用逗號(hào)分隔 s: invoice_id=id1,id2,id3
。當(dāng) Spring 處理此請(qǐng)求時(shí),它會(huì)看到您正在期待 a 形式的數(shù)據(jù)HashSet
,因此它將嘗試轉(zhuǎn)換id1,id2,id3
為 a HashSet<Integer>
,它知道如何自動(dòng)執(zhí)行此操作。
旁注:除非您特別需要 a HashSet
,否則使用接口而不是實(shí)現(xiàn)子類來聲明您的類型被認(rèn)為是一種好習(xí)慣。因此,在這種情況下,我建議將您的方法簽名更改為接受 aSet<Integer>
而不是 aHashSet<Integer>
添加回答
舉報(bào)
0/150
提交
取消