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