使用Postman传递arraylist数据给springboot方式

使用Postman传递arraylist数据给springboot

起因:需要做一个批量删除的功能,后台接收一个ArrayList ids

但是菜鸡小王不晓得postman 怎么传递集合数据给后端进行测试。

这个时候就只好发灰出csdn和百度的强大之处。

首先确定你的请求方式是什么

填写你的url路径

使用Postman传递arraylist数据给springboot方式_第1张图片

在这边补充一句 对象也是这样传递 以一个json 格式传递给后端。

后端接收的方法

    /*
     * 根据id 批量删除
     * @Param [ids]
     * @return com.crush.reponse.CommonsResponse
     **/
    @UseToken
    @DeleteMapping("/")
    @PreAuthorize("hasAuthority('ADMIN')")
    public CommonsResponse newsByType(@RequestBody ArrayList ids){
        return new CommonsResponse(newsService.deleteNewsById(ids));
    }

这里的@RequestBody用于读取Http请求的body部分数据——就是我们的请求数据。

比如json或者xml。然后把数据绑定到 controller中方法的参数上,这里就是String json这个入参啦~

Postman传递arraylist参数给springboot的controller

使用Postman传递arraylist数据给springboot方式_第2张图片

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

你可能感兴趣的:(使用Postman传递arraylist数据给springboot方式)