0


springboot后端接收前端传数组参数方法

1::前端传数组参数用ids,不要用ids[],因为是传数组会自动加上[]

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

2:使用postman传数组有三种方法

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

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

在这里插入图片描述

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

与@RequestBody不同,@RequestParam传递的数组中有多少个值,便排排下来写便是
(注意微操,参数名需为key的名称为@RequestParam括号里的名称,而不是定义的数组名)

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

在这里插入图片描述

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

@ApiOperation(value ="批量删除", notes ="批量删除")@DeleteMapping(value ="/batchDelete")publicResult<?>delete(@RequestBodyArrayList<Integer> ids){
        sysStudyTestFileService.removeBatchByIds(ids);returnResult.ok("删除成功");}

在这里插入图片描述

标签: spring boot java spring

本文转载自: https://blog.csdn.net/qq_19891197/article/details/128985327
版权归原作者 小徐敲java 所有, 如有侵权,请联系我们删除。

“springboot后端接收前端传数组参数方法”的评论:

还没有评论