目录

springboot后端接收前端传来的数组

springboot后端接收前端传来的数组

后端接收前端传来的数组参数

1 使用@RequestParam 接收数组

https://i-blog.csdnimg.cn/blog_migrate/8e71c350779192d1ec6f0f04addf8e8f.png

postman测试:

https://i-blog.csdnimg.cn/blog_migrate/1d2e4f99c8dc89ab442c9e193c5e0d85.png

2 使用@RequestBody 接收

https://i-blog.csdnimg.cn/blog_migrate/39fd9a972b56fb7f6cc5b380517658e7.png

postman测试:

注意要在请求体 body 中传 json 字符串。

https://i-blog.csdnimg.cn/blog_migrate/56ab5c49af1711f65f88f5ff65e3338b.png

结果:

删除前:

https://i-blog.csdnimg.cn/blog_migrate/c388079226473891eb3db4f46b3e77ca.png

删除后:

https://i-blog.csdnimg.cn/blog_migrate/7629e28d8b49546d2f2c7dab218c374c.png

两者的区别:

  • @RequestBody接收前端传来的 请求体 中的字符串

    因为get请求是没有请求体的,所以前端发送请求时要以post的方式发送

  • @RequestParam 接收url中的参数

总结:如果要将接收的数据在请求体中 用@RequestBody, 如果在url的参数中,用@RequestParam接收