user3841595
user3841595

Reputation: 1

Understanding the flow of spring framework & MVC

I am having some trouble understanding this. Can someone help me better understand this?

MVC 
Model --> Java- Spring Framework
View ---> templating language(JSP velocity) & Javascript 
DB --> SQL 

Q-1) Now, When I open a particular page, I can't visualize the flow. I've read about DAO, controller , service etc and I understand them individually but I am really confused when I club all together what's the order of execution? Whats the flow exactly ? Is it that first the view is loaded then it sends JS request to fetch the necessary data from backend and then the controller and service are invoked and the DAO queries the db? Then how does the API come into picture? DAO deals with the API?

Q-2) Why do we need xyz.properties? I have removed a module from my page. If I remove a particular js file(related to that module) from the scripts.properties, then ideally that js should not get executed at all right? Then still why would I see the api call to fetch the data related to that module? I don't see the module but I sure see the api call. Why is that?

Upvotes: 0

Views: 1312

Answers (2)

Oomph Fortuity
Oomph Fortuity

Reputation: 6108

In simple layman's term, MVC explained in pictorial form

    (inputing data)    (data related part)   (display rendering)
   -request mapping      -classes            -JSP (Script,CSS,HTML)
   -request param        -interface           -velocity  
     Controller ------------->Model--------------->View
                               ||
                               \/
            (data processing logic)    (access to Databse)
              -optimization                -JDBC
              -business logic              -SQL
                 Service--------------------->DAO  

Upvotes: 0

Luiggi Mendoza
Luiggi Mendoza

Reputation: 85779

DB doesn't enter in MVC model. And you're forgetting a principal element in your analysis: the Controller. The flow goes like this:

  • Client performs a request to an URL
  • The application server gets the URL and passes the handling to the web application.
  • The web application using Spring MVC will handle the URL processing to the Controller: DispatchServlet, which is a Servlet.
  • The DispatchServlet will try handle the URL. If there's an URL mapping, then it will pass it to the class (mapped in the spring.xml config or decorated with @Controller annotation).
  • This controller (which in fact is part of the model) will handle the request. It will call services, daos, etc (Model) and return the necessary data to complete the response to the DispatchServlet.
  • The DispatchServlet will finish the request handling and, in the end, will generate the results e.g. a text/json response, or it will forward to a JSP file (View).

For question two, I never have used such scripts.properties file, so I don't know what you're talking about. Usage of a properties file is to store application properties that should not change until an application redeploy. They have 3 main advantages:

  1. They can be easily manipulated by human users. It's no rocket science to add, edit or remove values.
  2. Since it is a plain text, it's easier to version using a version control system like SVN, Git or another of your preference.
  3. It provides a faster access since it is usually in the same disk as the application, so there's no much time penalty when accessing to its contents compared to a database configuration. But since it is in disk, it still has a disadvantage against RAM access only.

Upvotes: 4

Related Questions