Use List to receive multiple parameters with the same name.

Receive array or collection data,When the client passes multiple parameters with the same name, you can use array reception

?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";
}

When the client passes multiple parameters with the same name, you can also use a single column collection to receive it, but you need to use @RequestParam to tell the framework that the parameters passed need to be set with the same name, not object attribute settings. of

@GetMapping("/show")
public String show(@RequestParam List<String> hobbies){
    
    
    for (String hobby : hobbies) {
    
    
    	System.out.println(hobby);
    }
    return "/index.jsp";
}

Guess you like

Origin blog.csdn.net/rqz__/article/details/131992549