如题,这个功能点比较少见,但是也确实存在,这里记录一下。
只需要改一下传参的声明:变量改成数组变量。
@GetMapping("/test")
public Object test(@RequestParam(value = "str") String[] arr)
接口请求的时候有三种方式:
方式一:
test?str=12&str=13
方式二:
test?str=[12,13]
推荐方式一访问,方式二在 SpringBoot 2.0 以上会报 400 ,需要改配置,可以参考 springboot的get请求传入特殊符号报400错误(RFC 7230 and RFC 3986) - 简书 (jianshu.com),或者使用方式三
方式三:
test?str=12,13