zoukankan      html  css  js  c++  java
  • SpringMVC Failed to instantiate [java.util.List]: Specified class is an interface

    @RequestMapping("/test/save")
    public Result save(Integer threadNum, Integer pageIndex, Integer pageSize, Integer totalPage,  List<String> productCodes) {
    ...
    }
    

    SpringMVC中使用List<T>参数,用Postman测试接口报错,提示:

    org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.util.List]: Specified class is an interface
    SpringMvc报错解决:Failed to instantiate [java.util.List]: Specified class is an interface 
    

    解决方式:
    方法1:List参数加上@RequestParam(value = "productCodes")注解,调用方式不变

    @RequestMapping("/saveAllGroupProductPrice")
    public Result save(Integer threadNum, Integer pageIndex, Integer pageSize, Integer totalPage, @RequestParam(value = "productCodes", required = false) List<String> productCodes) {
    ...
    }
    

    方法2:请求参数封装为XxxReqvo,使用@RequestBody注解,改用application/json调用。

  • 相关阅读:
    ActiveMQ学习第八篇:Consumer
    ActiveMQ学习第七篇:Messaage
    线性判别分析LDA
    逻辑回归
    那些年,曾踩过的Spark坑
    HBase表创建、删除、清空
    python的多线程
    python的多进程
    python实现读写txt文件
    python的封包和解包
  • 原文地址:https://www.cnblogs.com/cdfive2018/p/13894985.html
Copyright © 2011-2022 走看看