Use a .Controller annotations
Examples 1. org.springframework.stereotype.Controller annotation type indicated Spring class, is a controller
2. Notes in the form of its @Controller.
3. The notes need not be implemented using the Controller interface and need to be applied to the controller class @Controller annotation, then the annotation found marked by a controller to scan the Spring mechanism.
Use two .RequestMapping annotations
After Spring controller class to find the appropriate annotation @Controller by , within the controller needs to know how each request is processed, which requires the use @RequestMapping annotation type, which is used to request a map or a method. On a label can be a class or method of use.
III. Returns the type of request processing method
Spring MVC supports common return types are as follows:
1.ModelAndView: You can add Model data, and specify the view
2.Model
3.Map
4.View
5.String: jump view, but can not carry data
6.void: using asynchronous request, it will only return data without branching view
7.HttpEntity<?>或ResponseEntity<?>
8.Callable<?>
9.DeferredResult<?>
Since ModelAndView type of failure to achieve decoupling between the data and view it in the enterprise development, the return type usually use String.
In addition to return a String view of the page in the code above, you can also redirect the request forwarding.
1.redirect redirection
2.forword request forwarding