Spring Boot Web MVC
Different Layers in Project a. Presentation Layer (PL) => User Interface(UI) / Web Pages (HTML, CSS, JS, JSP, Thymeleaf..etc) b. Service Layer (SL) / Business Layer (BL) (Calculations, Operations, logics, Transactions..etc) c. Data Access Layer (DAL) Database Operations (CRUD) d. Integration Layer (IL) Webservices (link your app with other apps) *) Spring Boot Web MVC is used to design PL Layer only.It is used to develop web pages (mainly dynamic pages). ie Change of data in webpage occures based on location,time,user. => Design pattern is used to imporve performance using MVC M = Model (Data) V = View (UI/Display) C = Controller (Class/process request) Spring Boot WEB MVC Execution Flow 1. Client Machine is operted by End user which has one browser software. Ex: Your Laptop, mobile..etc 2. Brower makes request when user operates it. Q) How many ways can browser makes request when user operates it 3 ways. a. Enter URL in Addressbar [GET] (ex: http://facebook.com) b. Click on Links (HyperLink/) [GET] c. HTML Form Submit (Register Form, Comment Form, Login Form,Payment..etc)[GET*/POST] 3. Every request is received by FrontController which is a pre-defined servlet (named as : DispatcherServlet) given by Spring WEB MVC. -> In case of Spring F/w we should configure using web.xml But in Spring Boot comes with auto-configuration sample org.springframework.web.servlet.DispatcherServlet sample / 4. HandlerMapping(memory) is created by Spring F/w at runtime by using all details of our controller classes.
For one MVC Project, there will be only one FC, HandlerMapper.*** It stores data as Map Format **** +--------------------------------------------------------+ | Key (Path+HttpMethod) Value(Class#Method) | +--------------------------------------------------------+ | | | /emp/save + POST EmployeeController#save() | | | | /prod/export + GET ProductController#exprt() | | | +--------------------------------------------------------+ 5. FC gives Path and Http Methods details as input taken by Request and reads back Class and Method details(Controller) 6. Now, FC will call/execute Controller#method. 7. Controller class contains request processing logic inside java methods linked with Path and Http Methods(GET/POST) => There will be multiple controller in a project, in general (1 Module - 1 Controller) Ex: SearchController, CartController, PaymentController...etc @Controller class PaymentController { @PostMapping("/pay") public String doPayment() { //logic } } FC calls like : paymentController.doPayment() for one request. => Controller provide Model(Data) in key=val format which can shared with UI(View) to display finally. key value message = "Payment SuccessFul"; 8. Controller clas finally returns ViewName(String) to FC ex: Home, Inbox, Search ..etc => Controller returns Viewname without any extension (tobe independent of UI technology)ie in future if we move from on UI tech to any other UI tech, controller code remains same. 9. FC is taking help of ViewResolver to get full details of View Name. 10. ViewResolver gives viewPage dtails returned to FC ViewPage = prefix + viewName + suffix (/mypages/Home.html) 11. Now, FC will call that page (execute UI page) 12. UI Page reads data from Model(if exist)into page using EL concept (such process is called as data rendering) ex: Welcome to ${user} , At Runtime : Welcome to 'SAM', Model(user=SAM) 13. This page data is given back to FC. 14. FC convert it into Response Format 15. Response is sent back to browser 16. Browser will display output.
=> Spring Boot provide 3 embedded Webservers.Even we can deploy on external server also.
a. Apache Tomcat (default) b. JBoss Undertow c. Eclipe Jetty => All objects (ViewResolver, HandlerMapping, Controller class, View ...etc )are created inside Spring container. => FC reads those objects from spring container.
Layers Design
MVC Design Pattern
OutLook of MVC Design
No Comments Yet!!