In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
First, the first is a MVC framework.
In the web model, MVC is a very popular framework. By separating the Model,View,Controller, the more complex web applications are divided into logical parts, in order to simplify development and reduce errors. Or for the cooperation between the developers in the group. In short, it is a way to work at different levels.
Second, springMVC, which is a subframework of spring, certainly has the features of spring, such as dependency injection.
Third, what is the information flow of springMVC?
First, the user requests to the server through HTTP, and the server will transfer the request to a different controller Controller according to your url. This is the first step, and what needs to be done is to set up the DispatcherServlet that maps URLpattern to spring in web.xml, which is the controller responsible for the first processing, which is used to forward the request, and it will forward the request to the appropriate Controller. So the question is, on what basis is it forwarded? This problem is a bit confusing because springMVC has been upgrading and contributing new url-to-Controller mapping methods. But everything remains the same, and no matter how it changes, its purpose remains the same, which is to try to establish a mapping from url to Controller, and once you find this goal, it looks easier. Specifically,
Method 1, in the configuration file of springmvc, directly write the name of bean into a url, as shown in
With this configuration, the request for url of / product_input is forwarded directly to the class ProductInputController.
Note: but this method is considered to be old-fashioned and is no longer popular. It is OK to understand, what is recommended now is the way of annotation, that is, the way of method 2.
Method 2, in this way, when naming the Controller, it doesn't matter. Its mapping does not depend on this name, so you can write the configuration of the bean in the following way, such as
At this point, it is obvious that the mapping from url to Controller has not been implemented, because url has not even seen it yet.
Now springMVC has an annotation RequestMapping, which is specifically responsible for mapping url, for example, the addProduct () method that needs to be mapped to ProductInputController. You only need to add a note to this method, such as
@ RequestMapping (name= "product_input")
AddProduct ()
With this annotation, you can map the product_input url to the addProduct method. Isn't it easy. In fact, they all do the same thing, but in a different way and in a different position.
It feels so magical, and I had this feeling at first, until I understood how the original Servlet connected url with the classes that deal with business, and found that the process was not so mysterious. Here I recommend a book, "SpringMVC Learning Guide" Paul Deck, which is suitable for people with 0 foundation. The example is very detailed.
Let me give you a rough idea of what happened from url to Controller:
The starting point is that if the user requests the server through HTTP, then there must be a URL, such as http://www.dudu.com/getName, where getName is my url. Suppose your servlet is deployed in tomcat. In the web.xml configuration file, there should be a url-to-class relationship, or through other annotated methods such as @ Webservlet (name= "xxController", urlPatterns = {"product_input"}). This means that after this url comes in. Leave the request to the class of xxController, which inherits the HttpServlet and overrides the doGet method, and your request will come to this method, and then, call the request.getRequestURI method inside the method, get your url=getName, and then the string matches equals, calling the later specific class.
The reason we use the framework is that in development, such steps are repeated and are the same every time, so the writer of the framework encapsulates such routine code and leaves the details to him to handle. We just need to do two things related to our business, one is to make sure url, and the other is, this url points to that class. This is basically the end of the story from url to Controller. There are two classes, one is DispatcherServlet, which is included in the SpringMVC framework, and the other is your own class that handles business, such as ProductController. Controller names like to be called XXXController. Draw a picture below to illustrate this step
Fourth, MVC, first of all, it is actually Cpene Controller, the following is View, that is, the view, display. Users' browsers see more beautiful web pages, which is HTML, which is responsible for displaying bitter data in various styles to make ordinary users look good, rather than a pile of JSON data. After the user's request comes in, it must be returned to the user's page, each page is a VIEW,view like a web page frame, the frame of a page is fixed, the difference is the data. The shopping cart page, for example, is a frame. Then your shopping cart and mine generally look the same, but the specific content is different, because the goods you buy are different, and this specific thing, or data, is Model. Now there are M and V.
The next string of this process, just said that the request has reached Controller, the role of this class is 1, select the appropriate view to return to the user, 2, organize the data, that is, generate Model. Network transmission and information technology mainly deal with data, but now the data is placed in Model, or the place where the data is placed is called Model. For example, if a user is requesting to query user information, what Controller does is to find the information in the database, then add the information to Model, and then return the Model and the corresponding View to DispatcherServlet. Here goes on to add to the previous picture:
Fifth, now that DispatcherServlet has got the data in Model and which View to use to show it to users.
So Model and View will be fused, specifically, the variables of View will be changed into specific values with the data of Model, and then the view will become a HTML page, and finally the HTML will be returned to the user, and the user will use the browser to explain the HTML, and see that it is a normal web page. The whole process is over.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.