首页 > 解决方案 > 如何在 Spring Boot 中搜索乘法(批量)参数?

问题描述

我想批量搜索这样的实体:

GET api/stuff?ids=123+456+789+101112+...

我发现可以像这样获取请求参数:

@RequestMapping(method = RequestMethod.GET, value = "/stuff")
public String controllerMethod(@RequestParam Map<String, String> customQuery) {

    //After that I could get 123+456+789+101112+... and I could parse them.
    String ids = customQuery.get("ids");
}

上述解决方案是否有替代方案,我可以将请求参数作为列表或任何其他解决方案?

标签: restspring-bootgethttp-request-parameters

解决方案


@GetMapping("/stuff")
public String controllerMethod(@RequestParam("ids") List<Integer> ids) {

}

那么你应该可以把它api/stuff?ids=123,456,789称为api/stuff?ids=123&ids=456&ids=678


推荐阅读