首页 > 其他分享 >Springboot api的controller如何接口一个List<Object>参数

Springboot api的controller如何接口一个List<Object>参数

时间:2023-06-21 11:12:49浏览次数:36  
标签:return Springboot HttpStatus deleteTestCaseList List controller api DBUpdateStat

1.正常情况下,你可能会这样写:

  @PostMapping("/delete")
    @ApiOperation("Delete  list data")
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public DBUpdateStatus deleteTestCaseDatas( List<TestCaseInfo> testCaseInfoList){
        try {
            testLinkService.deleteTestCaseList(testCaseDetailInfoList);
            return DBUpdateStatus.Success;
        }catch (Exception e){
            return DBUpdateStatus.Fail;
        }

    }

但是这样写,其实会报错:

 那么,正确的方式应该怎样写呢:

  @PostMapping("/delete")
    @ApiOperation("Delete  list data")
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public DBUpdateStatus deleteTestCaseDatas(@RequestBody List<TestCaseInfo> testCaseInfoList){
        try {
            testLinkService.deleteTestCaseList(testCaseDetailInfoList);
            return DBUpdateStatus.Success;
        }catch (Exception e){
            return DBUpdateStatus.Fail;
        }

    }

直接在该 含List参数的对象上,添加一个无参构造器,解决!

但并不知道原理是什么,路过的大神求解答~~

标签:return,Springboot,HttpStatus,deleteTestCaseList,List,controller,api,DBUpdateStat
From: https://www.cnblogs.com/pingguomang/p/17495762.html

相关文章

  • Springboot 框架中的Entity,Dao,Service,Controller的关系
    SpringBoot框架中的Entity,DAO,Service,Controller层的关系参考:https://blog.csdn.net/weixin_44532671/article/details/117914161https://blog.csdn.net/m0_47552180/article/details/125613332......
  • SpringBoot之MVC配置(WebMvcConfigurer详解)
    一:基本介绍SpringMVC是一种常用的JavaWeb框架,它提供了一种基于MVC模式的开发方式,可以方便地实现Web应用程序。在SpringMVC中,WebMvcConfigurer是一种常用的配置方式,可以允许我们自定义SpringMVC的行为,比如添加拦截器、消息转换器等。在本文中,我们将介绍什么是WebMvcConfi......
  • Springboot03
    1.Springboot引入JSPspring官网说,不建议springboot使用jspspring默认值支持Thymeleaf、FreeMarker·、Velocity·、GroovyJSP1.1.引入jsp相关的依赖<dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId>&l......
  • listView获得CheckBox 的位置
    当一个lsitView中每个ietm有多个控件的时候想获得其中的位置,其实主要是item的位置@OverridepublicViewgetView(intposition,ViewconvertView,ViewGroupparent){//grabviewViewv=convertView;//setviewlayoutif(v==null){LayoutInflatervi=......
  • listView中item 图文并存的两种方法
    1.<?xmlversion="1.0"encoding="utf-8"?><TextViewxmlns:android="http://schemas.android.com/apk/res/android"android:id="@android:id/text1"android:layout_width="fill_parent"......
  • SpringBoot学习笔记
    SpringBoot学习笔记学习资料分享,一定要点!!!示例代码跳转链接无效,查看完整笔记点击:https://gitee.com/pingWurth/study-notes/blob/master/springboot/spring-boot-demo/SpringBoot学习笔记.md官方文档:https://docs.spring.io/spring-boot/docs/current/reference/html/index......
  • Springboot web,三层架构, IOC&DI 使用总结2023
    Springbootweb,三层架构,IOC&DI使用总结2023一.spring.io全家桶springbootspringframework基础框架,配置繁琐,入门难度大--》springbootspringcloudspringsecurityspringdataspring发展到今天是一个生态圈,提供了若干个子项目,每个子项目用于完成特定的功能。二.sp......
  • Springboot实现WebSocket
    一、什么是webSocketWebSocket是HTML5下一种新的协议(Websocket协议本质上是一个基于tcp的协议),它实现了浏览器与服务器全双工通信,能更好的节省服务器资源和带宽并达到实时通讯的目的,WebSocket是一个持久化的协议。二、修改配置文件在application.properties,修改内容为:server.port=......
  • 【whale-starry-stl】01天 list学习笔记
    一、知识点1.std::bidirectional_iterator_tagstd::bidirectional_iterator_tag是C++标准库中定义的一个迭代器类型标签,用于标识支持双向遍历的迭代器类型。在C++中,迭代器是一种泛型指针,用于遍历容器中的元素。迭代器类型标签用于标识迭代器的特性,从而在算法中选择合适的......
  • 5步带你玩转SpringBoot自定义自动配置那些知识点
    目前SpringBoot框架真的深受广大开发者喜爱,毕竟它最大的特点就是:快速构建基于Spring的应用程序的框架,而且它提供了各种默认的功能和配置,可以让开发者快速搭建应用程序的基础结构。但是,当我们需要自定义一些配置时,我们就需要使用自定义自动配置。今天一定让大家深刻体验干货知识点......