This is basic Java and has nothing to do with Spring. Local variables and method parameters are initialized differently.
For a method parameter the initialization is implicit because you must give some value to the method call. Example:
// Declaration
public String showForm(Model theModel) {
}
// Call
showForm(null);
You cannot ommit the argument and so the method parameter is initialized with the value that you pass to the method call.
For a local variable it is different. If you just declare it without any value assignment the variable is not initialized. The following code would compile:
public String showForm() {
// Note the initialization with null!
Model theModel = null;
Student student = new Student();
theModel.addAttribute("student", student);
return "student-form";
}
Anyway, that would cause a NPE at runtime of course.
2
solved Spring Mvc method argumrnts