目录

前端传数组,后端怎么接收的问题

前端传数组,后端怎么接收的问题

js里数组和list的区分不是很明确?

总结:

对于get方式,前端传数组,后端就只能用数组接收(对象中有这个数组也可以用对象接收),不能直接用list接收(对象中有和前端传递的数组名相同的List,可以用该对象接收)

对于post方式,如果是json格式,后端list(建议,好操作,api多)或数组接收,加上@RequestBody即可;其它格式同get接收

比如我批量删除(Post+Json) :(这里的data不能设置参数名,直接this.ids)

https://i-blog.csdnimg.cn/blog_migrate/39676697892da0e30a0e47a7d061a3de.png

请求数据是这样的:

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

后端:list和数组接收都行

https://i-blog.csdnimg.cn/blog_migrate/8374263eb73187e7013b85acfd308cbb.png

https://i-blog.csdnimg.cn/blog_migrate/73e78176e79ba7d393de53fbaa4f48f0.png