gpt4 book ai didi

java - RequestParam as Set in 单个参数

转载 作者:行者123 更新时间:2023-11-30 06:03:08 25 4
gpt4 key购买 nike

我用设置的参数创建了端点:

@GetMapping("/me")
public MeDto getInfo(@RequestParam("param") Set<Integer> params) {
...
}

一切正常,但我需要单独发送 ID,例如

/me?param=1&param=2

有没有办法让它变成:

/me?param=1,2...N

有什么想法吗?谢谢。

最佳答案

你可以这样做

@RequestMapping(method=RequestMethod.GET, value="/me")
public ResponseEntity<?> getValues(@RequestParam String... param){
Set<String> set= new TreeSet<String>(Arrays.asList(param));
return new ResponseEntity<Set>(set, HttpStatus.OK);
}

所以如果你点击 --> localhost:8786/me?param=hello,foo,bar,animals ,你将得到以下响应

[ “动物”, “酒吧”, “富”, “你好”]

关于java - RequestParam as Set in 单个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53029982/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com