接收数组或集合数据,客户端传递多个同名参数时,可以使用数组接收
?hobbies=eat&hobbies=sleep
or
?hobbies=eat,sleep
@GetMapping("/show")
public String show(String[] hobbies){
for (String hobby : hobbies) {
System.out.println(hobby);
}
return "/index.jsp";
}
客户端传递多个同名参数时,也可以使用单列集合接收,但是需要使用@RequestParam告知框架传递的参数是要同名设置的,不是对象属性设置的
@GetMapping("/show")
public String show(@RequestParam List<String> hobbies){
for (String hobby : hobbies) {
System.out.println(hobby);
}
return "/index.jsp";
}

被折叠的 条评论
为什么被折叠?



