简体   繁体   English

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

[英]How to pass HashSet to server to test API from postman?

I created an API which I want to test using postman. 我创建了一个我想用邮递员测试的API。 My api is accepting many parameters and one parameter is HAshSet. 我的api接受了很多参数,一个参数是HAshSet。 I dont know how to pass HashSet parameter using postman. 我不知道如何使用邮递员传递HashSet参数。 Please help me. 请帮我。 Thanks in advance 提前致谢

Here is my code: 这是我的代码:

@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

}

A Set or HashSet is a java concept. SetHashSet是一个java概念。 There is no such thing as a Set from the HTTP perspective, and there is no such thing as a Set in Postman. 有一个这样的东西Set从HTTP的角度来看,并没有作为一个没有这样的东西Set在邮差。 So from Postman, you need to send the invoice_ids in a format that Spring's parsing library can convert to a HashSet . 所以从Postman,您需要以Spring的解析库可以转换为HashSet的格式发送invoice_ids As @Michael pointed out in the comments, one way to do this is to comma separate the invoice_id s like this: invoice_id=id1,id2,id3 . 正如@Michael在评论中指出的那样,一种方法是用逗号分隔invoice_id如下所示: invoice_id=id1,id2,id3 When Spring processes this request, it will see that you are expecting data in the form of a HashSet , so it will attempt to convert id1,id2,id3 into a HashSet<Integer> , which it knows how to do automatically. 当Spring处理这个请求时,它会看到你期望HashSet形式的数据,所以它会尝试将id1,id2,id3转换为HashSet<Integer> ,它知道如何自动执行。

Side note: Unless you specifically need a HashSet , it is considered good practice to declare your type using the interface instead of an implementing subclass. 旁注:除非您特别需要HashSet ,否则使用接口而不是实现子类声明类型被认为是一种好习惯。 So in this situation I would recommend changing your method signature to accept a Set<Integer> instead of a HashSet<Integer> 所以在这种情况下,我建议更改方法签名以接受Set<Integer>而不是HashSet<Integer>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从HashSet正确传递/添加字符串 <String> 在另一个,HashSet <String> ? - How to correctly pass/add Strings from HashSet<String> in another, HashSet<String>? 如何在 RES 中将 hashmap 作为有效负载传递以及如何通过 POSTMAN 对其进行测试 - How to pass hashmap as payload in RES and how to test it through POSTMAN 无法通过Postman在Java Server上测试Google Cloud Endpoints - Unable to test Google Cloud Endpoints on Java Server from Postman 如何使用邮递员测试提供 .zip 文件的 REST API? - How to test REST API which serve a .zip file using postman? 如何使用 Spring Boot Web Authentication 和 Postman 测试 API? - How to test API with Spring Boot Web Authentication and Postman? 如何测试HashSet是否在TextField中包含某些内容 - How to test if a HashSet Contains something in a TextField 如何从 curl 或 postman 或 swagger Micronaut 传递值 @Body MultipartBody - How to pass the value @Body MultipartBody from curl or postman or swagger Micronaut 如何从HashSet中删除元素? - How to Remove an element from HashSet? 如何从方法返回HashSet? - how to return HashSet from a method? 如何使用邮递员或API从“下载”文件夹中下载文件 - How to download file from a “Download” folder using postman or API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM