Java web MVC development model, javamvc

Source: Internet
Author: User

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 (data persistence layer), viewer (view layer), and control (control layer.

The development advantage of MVC is very obvious. The model layer consists of javaBean and service, and Bean is mainly used for persistent data acquisition, for example, retrieving data from the database and assigning data to bean objects, with the feature of access permission, its attributes can only be obtained through method access, but cannot be accessed directly. service mainly uses bean data for business logic processing to return the required data.

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 or service 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. (I am an entry-level programmer. These are my insights on a small project .)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.