No primary or single public constructor found for interface java.util.List - and no default construc

SpringBoot接收List类型的参数报错

  • 问题背景

    在写瑞吉外卖时,我想进行批量删除,使用List去接收选中的记录的id,但是在点击删除按钮后,后端直接报
    No primary or single public constructor found for interface java.util.List - and no default construc,后端压根就没有接受到前端传过来的参数,

  • 问题原因

    对于对象类型的数据,特别是请求头参数,需要使用@Request注解进行映射,否则SpringMVC不知道该如何转换

  • 解决方案

    • 方案一:不使用List ids来接收,改用 Long[] ids来接收
    • 方案二: 在List ids前添加@Request注解,告诉SpringMVC,将前端传过来的请求头参数转换成List集合的形式
      在这里插入图片描述

    PS:本人是使用方案二,成功解决了问题O(∩_∩)O,如果觉得对你有帮助,麻烦帮俺点个赞

猜你喜欢

转载自blog.csdn.net/qq_66345100/article/details/130267198
今日推荐