Controllers in detail

Controllers, with their methods annotated with @RequestMapping, handle web requests. They accept input data in multiple forms and transform them into Model attributes to be consumed by views that are displayed back to the client. They connect the user to service-layer beans, where your application behavior is defined.

A Controller in Spring MVC has the following signature:

public interface Controller {

   ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception;
}

A Controller is designed as an interface, allowing you to create any kind of implementation. Starting from Spring version 2.5, you can turn any class into a Controller just by annotating it with @Controller. It relieves you ...

Get Spring MVC: Designing Real-World Web Applications now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.