View
Learn how to create a view template and resolve a view name.
We'll cover the following...
When a controller or handler returns a response back to the dispatcher servlet, it is either shown as it is to the user (if the @ResponseBody
annotation is present), or a view is called.
In real world applications, we do not return String
responses back to the user. We redirect the user to a view or JSP.
Redirecting to a view
Say, we want a request to "/"
to be redirected to main-menu.jsp
. We can return the view name as follows:
Press + to interact
@RequestMapping(value = "/")public String welcome() {return "main-menu";}
The return value main-menu
will be treated as the name of a view now, because we have removed the @ResponseBody
annotation from the ...