Sunday 17 December 2017

Java and liferay Spring MVC with annotation

Q-What is spring mvc?
ans-Spring  MVC is design pattern which provide seperation of presentation layer and business layer
It provides solution to layer an application by separating three concerns business, presentation and control flow. Model contains business logic, controller takes care of the interaction between view and model. Controller gets input from view and coverts it in preferable format for the model and passes to it. Then gets the response and forwards to view. View contains the presentation part of the application.

    • The model is contract between controller and view, Model represents data of the application , it contain service layer and data acccess alyer also it has setter and getter method basically model is simple java class which generates dao and dto classes
    • The view is  responsible for particular jsp page and html page what you displaying on UI ...visualization of your model.
    • The controller manages complete lifecycle of application, it is responsible for recieving the request from user and calling backend servicess and makes calls into business objects.


DispatcherServlet

Purpose of dispatcher is recieve the request & map those request to the correct resource such as controller, model & views

DispatcherServlet is the class that manage the entire request handling process.

Spring MVC Advantage:-
1-reusing component
2-Modifying in one layer will not effect   other layer.







Spring MVC 3.0.0 Execution Flow:-

1-The DispatcherServlet first receives the request.
2-The DispatcherServlet consults the HandlerMapping and invokes the Controller associated with the request.
3-The Controller process the request by calling the appropriate service methods and returns a ModeAndView object to the DispatcherServlet. The ModeAndView object contains the model data and the view name.
4-The DispatcherServlet sends the view name to a ViewResolver to find the actual View to invoke.
5-Now the DispatcherServlet will pass the model object to the View to render the result.
6-The View with the help of the model data will render the result back to the user.
    
In Spring MVC we have presentation layer,controller layer,service layer and model layer.
Suppose from presentation layer we have return suppose login.jsp, in
When we click on submit button than one url will be found with that url request will be forward to the server,
-on server in web.xml you have configured dispatcherServlet  here dispatcherServlet is the frontController for spring mvc.

DispatcherServlet test client request, it will take url pattern, Using URL Pattern it will contact one component of spring mvc called handlerMapping.

handlerMapping is responsible to take URL, based on that url it will identify which controller class of your application, which method is responsible to process url pattern, so that controller class information and method releted information will send back to the dispatcher.

Finally controller class that particular method will be called, in that method if you use service class that object will be created, it will contact database model layer.

From controller class you returning some string that is viewlogical name that will come to dispatcherServlet.

again dispatcherServlet will give view logical name to the viewResolver, viewResolver is responsible to take string , it will add prefix and suffice

view will be render to the client, view will be return to dispatcherServlet and it will display to client


Liferay Spring MVC Annotation:
1-@RequestMapping("VIEW")
2-@RenderMapping(params = "action=saveRecord")
3-@ResourceMapping(value = "getStateCountry")

No comments:

Post a Comment