I’m used to Java EE but not Spring MVC. I’ve just created a new Spring MVC project and in the controller I have the following code generated.
@Controller
public class LoginController {
private static final Logger logger = LoggerFactory.getLogger(LoginController.class);
/**
* Simply selects the home view to render by returning its name.
*/
@RequestMapping(value = "/", method = RequestMethod.GET)
public String login(Locale locale, Model model) {
logger.info("Welcome home! the client locale is "+ locale.toString());
return "home";
}
}
Normally, I would expect one of the parameters to be request and the other response, how do I find these values with Spring MVC? For instance, I want to capture a username and password that will get sent here? Is there something similar to a doGet and doPost method in Spring MVC?
If you want to capture parameters called
usernameandpassword, then just declare them as method parameters:Spring will supply them, or throw an exception if they’re not present.
You could equally declare an
HttpServletRequestparameter if you choose to:But the first approach is cleaner.