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调用。

  • 相关阅读:
    tp5 thinkphp5 伪静态修改 fastadmin
    ThinnkPHP内置视图循环语句
    PHP禁止重写策略
    冒泡排序
    Ruby--正则
    JS正则
    JS禁止父元素事件
    Rails--default_scope
    公网映射
    查企业情况和招聘的网站
  • 原文地址:https://www.cnblogs.com/cdfive2018/p/13894985.html
Copyright © 2011-2022 走看看