spring报错:
2021-12-01 09:51:41.548 ERROR 3884 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: No primary or default constructor found for interface java.util.List] with root cause java.lang.NoSuchMethodException: java.util.List.() at java.lang.Class.getConstructor0(Class.java:3082) ~[na:1.8.0_162] at java.lang.Class.getDeclaredConstructor(Class.java:2178) ~[na:1.8.0_162] at javax.servlet.http.HttpServlet.service(HttpServlet.java:660) ~[tomcat-embed-core-9.0.35.jar:9.0.35] at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) ~[tomcat-embed-core-9.0.35.jar:9.0.35]
先直接说原因:
@PostMapping("/test/param/list")
public void testParamList(@RequestParam(value = "param") List param) {
System.out.println(param);
}
方法上少了注解@RequestParam(value = "param")
但是如果参数使用数组形式,就不用加这个注解了,如:
@PostMapping("/test/param/list")
public void testParamList(String[] param) {
System.out.println(param);
}
测试代码示例:
HTML:
Title
java代码:
@RestController
@RequestMapping("/DemoController")
public class DemoController {
@PostMapping("/test/param/list")
public void testParamList(@RequestParam(value = "param") List param) {
System.out.println(param);
}
}
如果不加注解@RequestParam(value = "param"),就会报No primary or default constructor found for interface java.util.List]


![No primary or default constructor found for interface java.util.List] No primary or default constructor found for interface java.util.List]](http://www.mshxw.com/aiimages/31/632310.png)
