美文网首页
[2019/05/17]解决springboot测试List接口

[2019/05/17]解决springboot测试List接口

作者: 山枫叶纷飞 | 来源:发表于2019-05-17 15:22 被阅读0次

    报错信息,大致如下

    c.c.c.c.a.BaseControllerExceptionHandler : 运行时异常:
    java.lang.IllegalStateException: No primary or default constructor found for interface java.util.List
    at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute(ModelAttributeMethodProcessor.java:212)
    ......
    WARN 18472 --- [nio-9090-exec-2] .m.m.a.ExceptionHandlerExceptionResolver : Resolved exception caused by Handler execution: java.lang.IllegalStateException: No primary or default constructor found for interface java.util.List


    再次修改后仍又报错:

    org.springframework.http.converter.
    HttpMessageNotReadableException: Required request body is missing:


    (以上报错信息谷歌翻译了一遍,大致知道了是属性接收异常和http消息转换异常)

    原因 : 接口不规范, 后端一时快, 前端两行泪
    第二次报错原因, @RequestBody这个标签在post 、put 方法中用于接收json格式的数据 ,get方法不行! get方法不行!
    第一次报错原因, @RequestBody用来接收一个List当做整体, 不要用@RequestParam--JSON格式的list没法实现对应了, 也不要错误写成@Param~~
    规范写法
        @ApiOperation(value = "批量删除")
        @PostMapping(value = "delBatchIds")
        public Boolean delBatchIds(@RequestBody List<Long> ids){
            return xxxxxService.deleteBatchIds(ids);
        }
    
    再次测试,OK
    image.png
    image.png

    相关文章

      网友评论

          本文标题:[2019/05/17]解决springboot测试List接口

          本文链接:https://www.haomeiwen.com/subject/nbinaqtx.html