29 December 2020

Controller Class

  • @Controller is used in spring mvc to define the controller which are the first bean and then the controller. This makes it as a spring bean class. And this needs to be maintained in the Spring Application Context
  • @RequestMapping: This is mainly for the presentation layer
  • @Service is used to define the service class which holds the business logic in the service layer
  • @Repository is used in Data Access layer

Types of Controller

Front Controller 
  • It’s a single servlet (Dispatcher Servlet) which is responsible for receiving the request, delegate processing to other components of the application and return response to the user.
Simple Form Controller

  • It’s used to control form data in web applications
  • It offers form submission support and uses model/command object
  • Supports features like invalid form submissions, validating form data  and normal form workflow
  • If we need to handle form this controller should be used
  • It also handle model object for binding and fetching data

Abstract Controller

  • Supports caching
  • Provides abstract methods which should be overridden by the subclass. 
  • handleRequestInternal(HttpServletRequest, HttpServletResponse)

Parameterizable view controller

  • Returns view name specified in spring configuration xml file thus eliminates the need of hard coding view name in the controller class as in case of Abstract controller.
  • This controller is used when you don’t need  to implement any logic in controller and just want to redirect to another view.

Multi Action Controller 

  • Supports aggregation of multiple request handling methods into one controller and also allows you to group , related functions together. 
  • It is capable of mapping requests to method names and then invoking the correct method to handle the particular request.

No comments:

Post a Comment

Most views on this month