Get方式传递数组与java后端接收

朋友提出的需求,后端需要get请求接收一个id数组。
后端测试代码:

/**
 * @author chunhui.tan
 * @version 创建时间:2018年11月19日 下午5:05:37
 *
 */
@RestController
public class TestController {
	
	@GetMapping("/test1")
	public void test1(@RequestParam Integer[] ids) {
		if (null != ids) {
			for (Integer integer : ids) {
				System.out.println(integer);
			}
		}
	}
}

前端的url需要写成这个样子

http://localhost:8080/test1?ids=12&ids=11

即多个参数名一样,spring会自动封装到一个数组中
控制台打印如下:

12
11


版权声明:本文为qq_38846242原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。