亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將 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 關注
  • 90 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號