SpringBoot接收GET请求中的数组、Map集合参数

时间:2025-03-20 08:16:23

本文主要有以下内容:

  1. SpringBoot 如何接收HTTP Get请求中的数组参数?

  2. [: No primary or default constructor found for interface ] 报错如何解决?

一、SpringBoot2.2.4接收数组参数

需要配合使用 @RequestParam注解

注: 如果你使用 Domain对象,则没有这个限制。

@GetMapping("/api/foos")
@ResponseBody
public String getFoos(@RequestParam List<String> id) {
    return "IDs are " + id;
}

验证结果: 
http://localhost:8080/api/foos?id=1,2,3
----
IDs are [1,2,3]

参考连接

  • RequestParam注解(baeldng 是一个 spring学习网站,有很多资料可以学习)

  • SpringBoot 接收List参数

二、SpringBoot接收数组参数报错

[: No primary or default constructor found for interface 
 ]

Caused by: : .<init>()
    at .getConstructor0(:3082)
    at (:2178)
    at (:216)

解决方案:

原因就是没有使用 @RequestParam注解

报错参考链接:
SpingBoot参数接收List数组报错