When springmvc's controller gets parameters, what's the difference between the following two ways? why add the @ parameter?

1. Write the parameters of the form directly in the formal parameters of the corresponding method of Controller
public String addUser1 (String username,String password)
and bind the request parameter
public String addUser6 (@ RequestParam ("username") String username)

) with the annotation @ RequestParam

2. Receive
public String addUser3 (UserModel user)
and FORM form data
public String addUser5 (@ ModelAttribute ("user") UserModel user)

) of the POST request using the @ ModelAttribute annotation through a bean
Feb.28,2021

@ RequestParam: if @ RequestParam is used in the method, the argument will only be injected into the parameter labeled @ RequestParam

bean: is automatically injected into the parameter that satisfies the argument name

Menu