方式一
可以将数组参数传递多次,springmvc会将多个同名参数自动封装成数组或者集合对象,示例如下:
# 请求URL
http://127.0.0.1:8080/getUsers?name=张三&name=李四
# 后台接口代码
@RestController
@RequestMapping("/")
public class SpringMvcController {
@RequestMapping(value = "/getUsers", method = RequestMethod.GET)
# String[] name也可以切换为List<String,String> name
public String getUsers(@RequestParam String[] name) {
return name[0] + " " + name[1];
}
}
方式二、
直接将数组指用逗号分隔,示例如下:
# 请求URL
http://127.0.0.1:8080/getTeachers?name=王五,刘麻子
# 后台接口代码
@RestController
@RequestMapping("/")
public class SpringMvcController {
@RequestMapping(value = "/getTeachers", method = RequestMethod.GET)
# String[] name也可以切换为List<String,String> name
public String getTeachers(@RequestParam String[] name) {
return name[0] + " " + name[1];
}
}
标签:getUsers,name,GET,String,数组,请求,public,RequestMapping From: https://blog.51cto.com/chengzheng183/6350507