日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

springboot后端接收前端傳數組參數方法

作者:小徐敲java 更新時間: 2024-04-07 編程語言

1::前端傳數組參數用ids,不要用ids[],因為是傳數組會自動加上[]

	@ApiOperation(value = "批量刪除", notes = "批量刪除")
    @DeleteMapping(value = "/batchDelete")
    public Result<?> delete(@RequestParam(name = "ids[]", required = true) ArrayList<Integer> ids) {
        sysStudyTestFileService.removeBatchByIds(ids);
        return Result.ok("刪除成功");
    }

2:使用postman傳數組有三種方法

2-1:方法一,后端使用@RequestParam接收傳參

	@ApiOperation(value = "批量刪除", notes = "批量刪除")
    @DeleteMapping(value = "/batchDelete")
    public Result<?> delete(@RequestParam(name = "ids[]", required = true) ArrayList<Integer> ids) {
        sysStudyTestFileService.removeBatchByIds(ids);
        return Result.ok("刪除成功");
    }

在這里插入圖片描述

2-2:方法二,后端使用@RequestParam接受收傳參

與@RequestBody不同,@RequestParam傳遞的數組中有多少個值,便排排下來寫便是
(注意微操,參數名需為key的名稱為@RequestParam括號里的名稱,而不是定義的數組名)

    @ApiOperation(value = "批量刪除", notes = "批量刪除")
    @DeleteMapping(value = "/batchDelete")
    public Result<?> delete(@RequestParam(name = "ids[]", required = true) ArrayList<Integer> ids) {
        sysStudyTestFileService.removeBatchByIds(ids);
        return Result.ok("刪除成功");
    }

在這里插入圖片描述

2-3:方法三,后端使用@RequestBody接受收傳參

    @ApiOperation(value = "批量刪除", notes = "批量刪除")
    @DeleteMapping(value = "/batchDelete")
    public Result<?> delete(@RequestBody ArrayList<Integer> ids) {
        sysStudyTestFileService.removeBatchByIds(ids);
        return Result.ok("刪除成功");
    }

在這里插入圖片描述

原文鏈接:https://blog.csdn.net/qq_19891197/article/details/128985327

  • 上一篇:沒有了
  • 下一篇:沒有了
欄目分類
最近更新