Java web MVC development model, javamvc
When I was developing the first complete java web project, I had a clear understanding of the previous Java web knowledge system. I think it is very necessary to summarize this.
MVC refers to the basic development and combination modes of model (model layer), view (view layer), and control (control layer.
The development advantage of MVC is very obvious. The model layer is mainly composed of javaBean and so on. For a module, JavaBean is a library specially used to store data, and its instance object is set .. () method to write data, through get .. () method to retrieve data, which is independent. Any other program can use its instance object to access data through package adjustment.
The view layer is a view layer used to express content. The JSP page is added with a "compiler" that can interpret java code on the html page ", this allows jsp pages to process business logic on the basis of expressing content. When the JSP page has the ability to process data, it can receive data from other pages or programs and display the data, in order to better facilitate the expression of data content, it also provides el and jstl tags that can access attributes in various domains on the server. Common domains include "request, session, application, response ", the lifecycle of each domain is different. To accurately access the value, you must understand the lifecycle of the domain. Jsp pages can also process business logic, so it can replace the control layer, but this is contrary to the concise, efficient, and clear concept (just like html, css, and js ), in addition, the view layer is messy and bloated, which is not conducive to re-development and maintenance.
The control layer is the control layer, which is generally implemented by servlet files on the web. It extracts data from JavaBean and various domains, performs logical processing on the data, and completes related functions, the obtained data is transmitted to the view layer through the attributes of the domain and the lifecycle of the domain. The control layer is the soul of MVC and the most critical part, because the business is implemented here. In the end, it is here to design Java programs. However, in actual development, developers have developed many development modes to further simplify servlet. Here, we take the factory method as an example. The development process is as follows:
First, determine the modules and define an interface (DAO) for each module. In the interface, design the abstract methods required for implementation of this module;
Then, define a DAOImpl to design and implement all the abstract methods in the DAO layer.
In this way, you only need to call the methods in this implementation class in the servlet File to implement relevant functions, without further designing.
In addition, a Factory class is designed for each interface, and the static method is defined to return the instance object of an interface implementation class, that is, every time you call this static method with the factory class name and generate an instance object that implements the interface, it is like a factory, so it is called a factory method.