1, what is the MVC pattern?
MVC (Model View Controller) is a design pattern that uses an MVC application to be divided into three core components: models, views, controllers. Each of them handles its own task. M refers to the data model, v refers to the user interface, and C is the controller. The purpose of using MVC is to separate the implementation code of M and v so that the same program can be applied to different representations.
MODEL: Encapsulates all the business logic and rules. Typically implemented by JavaBean or EJBS.
VIEW: Use the results of business logic and build the response that is presented to the client. usually implemented by JSP.
CONTROLLER: Manages and controls the interaction between all users and applications. Typically, a servlet receives a user's request and forwards all input to the actual work model. The last call to the JSP returns output.
Benefits of the MVC pattern:
1. Individual duty, Non-interference
In the MVC pattern, three tiers are applied to each other, so if one layer of requirements changes, you only need to change the code in the corresponding layer without affecting the code in the other layers.
2. The Division of labour in favour of development
In the MVC pattern, because the system is opened by layer, the Division of labor in the development can be better realized. Web designers can develop the JSP in the view layer, and developers who are familiar with the business can develop the business layer, while other developers can develop the control layer.
3. Beneficial to the reuse of components
Tiering is more beneficial to the reuse of components. If the control layer can be used independently as a component, the view layer can also be made into a common operating interface.
Struts is a framework based on the MVC pattern. Describe the value stack structure of Struts2, and how does it work?
Value Stack value stacks
The value stack is the core concept of the STRUTS2 framework. All of the core components interact with it in some way, providing access to the context information and the elements in the execution environment. The content of the value stack consists of the following 4 levels.
1. Temporary objects
These objects need to be temporarily saved in request processing, such as elements in the collection that are currently being iterated.
2. Model objects
When the action implements the Modeldriven interface, the model object is stored on the stack, in front of the action object. If the action does not implement the interface, the content of this level will not exist.
3.Action objects
This object is the currently executing action.
4. Named object is OGNL context environment
Any object can be given an identifier and become a named object. The named objects built in Struts2 are: #application, #session, #request, #attr, #parameters
Using the value stack does not require a stack and stack, you can use the OGNL expression to find or evaluate the value directly. The OGNL expression is tested at each level, and the order of the hierarchy tests is in a hierarchical order. If no results are obtained at each level, a null value is returned. What implicit object is inside the Struts2.
An implicit object of Struts 2.1
(All of these implicit objects are map types)
Parameters used to access request parameters
The properties that the request uses to access HttpServletRequest
The session is used to access httpsession properties
Application properties used to access ServletContext
Attr is used to access the properties within each scope, and then searches the actions of the request > Session > Application Struts2 to get the request object in several ways.
1. Access through Actioncontext.getsession
2. Access through Servletactioncontext.getrequest ()
3. Injection through the Sessionaware interface
4. Through the Servletrequestaware interface injection please tell me your understanding of the Struts2 interceptor.
The Struts2 interceptor is an implementation of AOP by accessing a method of an action or action, blocking it before or after the field, and the Struts2 interceptor is pluggable.
The Interceptor Stack (interceptor stack) is similar to a filter chain. The interceptor stack is a chain that connects the interceptor in a certain order. When you access an intercepted method or field, the interceptor for the interceptor stack is invoked in the order in which it was previously defined.
Struts2 interceptors are similar to filter filters. Before executing the action's Execute method, Struts2 first executes the interceptor referenced in Struts.xml, completes a series of functions, and executes the action execute method after executing the Intercept method of all the referenced interceptors.
6. What is ORM thinking. What are the commonly used frameworks based on ORM? Each have what characteristics.
The full name of ORM is Object-relational Mapping, the Object relational mapping. The idea of ORM originates from the contradictory characteristics between the object and the relationship. It is very difficult for us to describe the relationship between a pair of one or one pairs and many pairs of data tables through the inheritance and aggregation of objects. The principles of abstraction and polymorphism in object-oriented thinking cannot be demonstrated through the SQL statements of relational databases. Therefore, we need to find a balance between object-oriented and relationship-oriented, and ORM arises.
The current ORM framework has so many products that, in addition to the large companies and organizations, some small teams are also rolling out their ORM frameworks. The current popular ORM framework has the following products:
(1) enitiy ejb:enitiy EJB is actually an ORM technology, which has been a controversial component technology. In fact, EJB has earned a high reputation for the development of Java EE, and EJB has an incomparable advantage as a heavyweight, expensive ORM technology. In terms of other architectural design, it is still very good. Even the lightweight Java EE architecture, which is now very popular, is essentially an imitation of the classic Java EE architecture-albeit with a little bit of improvement. EJB3.1 has also adopted a low invasive design that adds annotation and is also of great appeal.
(2) Hibernate: The most popular open source ORM framework has been chosen as a persistence layer solution for JBoss. The whole Hibernate project also invested in the embrace of JBoss, and JBoss joined the Redhat organization, so now hibernate belong to Redhat part. Hibernate Smart design, excellent performance, as well as its rich documentation is a major factor in the global popularity.
(3) Ibatis:apache the Software Fund organization. Rather than an ORM framework, call it a "SQL Mapping" framework. Has played a very important role in the development of Java EE, but is now gradually being replaced because it does not support the existence of object-oriented operations. But in some companies, there is still a niche, especially where data access is particularly flexible and ibatis more flexible, allowing developers to write SQL statements directly.
(4) Toplink:oracle Company's products, as a commercial product that follows the OTN agreement, TopLink can be freely downloaded and used in the course of development, but charges will be charged once used as a commercial product. Because of this, TopLink market share is not high.
(5) Obj:apache the Software Fund organization. Another open source ORM framework, it can be said that Apache as a replacement after the Ibatis product, but also a very good O/R mapping framework, but because of the hibernate is too large, so there is no widespread use, and because the OJB of the development of documents are not many, This also affects the popularity of OJB.
7. Please tell me your understanding of hibernat. What are the advantages and disadvantages of JDBC and hibernate.
Hibernate is a lightweight, persistent layer of open source framework, a middleware that connects Java applications and relational databases, and is responsible for mapping between Java objects and relational data. Hibernate internally encapsulates the JDBC API, Responsible for the persistence of Java objects. Because it encapsulates all the data access details, the business logic layer can focus on implementing the business logic.
It is an excellent ORM mapping tool that provides a sophisticated object-relational mapping service, which is not dependent on containers, is very flexible and can be seamlessly integrated into any Java system.
Both JDBC and hibernate are used for data persistence operations.
Jdbc:
1. The code that implements the business logic and the code that accesses the database mix together, making the program structure unclear and readability poor.
2.Java is object-oriented, and SQL is relational. The two are mixed, and programmers cannot use object-oriented thinking entirely to write programs.
3. Business logic and relational data model bindings, if the relational data model changes (such as changing the table structure), it is necessary to manually modify all the relevant SQL statements in the program, increasing the difficulty of maintaining the software. If the SQL statement has syntax errors, compilation is not able to check the error, only the runtime can find the error, Increase the debugging difficulty of the program.
4. Database migration is difficult.
Hibernate:
Hibernate is an open source Object Relational mapping framework that has a very lightweight object encapsulation for JDBC, making it possible for Java programmers to manipulate the database with arbitrary object programming thinking.