有时候我们前端会传一些 list 集合的参数,如果 list 集合的存储的类型是对象,通过 json 就可以封装,后端使用注解 @RequestBody 可以接收。如果是想传递通过装箱后的基本类型的 list ,需要使用到注解 @RequestParam。

后端没有使用 @RequestParam,swagger和postman传参数就会报这个错误

Request processing failed; nested exception is java.lang.IllegalStateException: No primary or default constructor found for interface java.util.List

报错
报错
加上 @RequestParam 注解

@RequestParam("idLists") List<Long> idLists

传参方式有两种
一种是直接写成以英文逗号分开的字符串:
传参一
接收参数
另外一种就是分开传参:
传参二
接收参数

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐