You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Postman中向接收HashSet参数的API发起测试请求?

How to Pass a HashSet<Integer> Parameter (invoice_id) in Postman for Your Spring Boot API

Hey there! I get it, figuring out how to send collection-type parameters in Postman can be tricky at first. Let me break down exactly how to test your collectMultiInvoices API properly.

Since your API uses @RequestParam for the invoice_id parameter (typed as HashSet<Integer>), Spring MVC makes this straightforward—you just need to pass the parameter multiple times (once for each integer in your set) in the request's query parameters. Here's step-by-step:

  1. Open Postman and load your PUT request for the API endpoint.
  2. Switch to the Params tab (this is where query parameters live).
  3. Add the invoice_id parameter repeatedly for each integer you want to include:
    • First, enter invoice_id as the key, and your first integer value (e.g., 123) as the value.
    • Click the Add button to create a new parameter row, again use invoice_id as the key, and enter your next integer (e.g., 456).
    • Repeat this for every integer you need in the HashSet.
  4. Add all your other required/optional parameters (like date, cash, chequeAmount, etc.) in the same Params tab just like you would with any regular parameter.
  5. Send the request—Spring will automatically collect all the invoice_id values into a HashSet<Integer> and pass it to your invoiceIds parameter.

Alternative: Comma-Separated Values (If Configured)

If you prefer, you can also pass all integers in a single invoice_id parameter separated by commas (e.g., invoice_id=123,456,789). For this to work, you might need to add a small configuration to your Spring Boot app to enable comma-separated value parsing for collections:

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(String.class, HashSet.class, source -> 
            new HashSet<>(Arrays.asList(source.split(",")))
        );
    }
}

That said, the first method (repeating the parameter) is the default behavior and doesn't require any extra configuration, so it's the simpler route.

Just to confirm, your existing controller code is set up correctly to handle this—Spring's @RequestParam automatically maps multiple query parameters with the same name to a collection type like HashSet.

内容的提问来源于stack exchange,提问作者Ankit Srivastava

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 05:32:41