1. request session application Lifecycle
1. The request is stored in each page request between the client and the server.
2. session ends when the client is disconnected, that is, the browser is closed.
3. After the application is closed on the server, the client browser can still access the historical data of the application.
Ii. Use of international resource files
That is, the configuration file with the suffix ". properties", which contains key-value pairs to set some parameters. For example, the country language setting and user information setting of the webpage
3. built-in converter: converts the data type in the program to the string type required by the webpage.
Data Verification: To meet the program requirements, the client usually uses Javascript to add data verification functions, such as user name character digit verification and mailbox format verification. However, in order to prevent hackers from using illegal input attacks, such as performing operations on the client webpage, deleting the client's javascript data verification, illegal input, and submitting webpage requests to the server, causing damage to the server. To prevent illegal input, the server also needs to add input verification. This verification method requires multiple requests to the server, which is less efficient than client verification.
4. Three states of objects in hibernate:
1. The temporary state is the object just instantiated.
2. Persistence status. The temporary object data has been written to the database.
3. After the session is closed, the persistent object associated with the session becomes the managed object. If the managed object is re-associated to a new session, it will be converted to a persistent object again.
The three statuses are converted as follows:
4. The most commonly used hibernate database operation statements are hql QBC. Refer to the blog post: Click to open the link.
QBC (Qurey By Criteria) Retrieval Method
When using HQL retrieval, you must define a string-based HQL query statement in the application. The qbc api provides another method for retrieving objects. It consists of the Criteria interface, Criterion interface, and Expression class. It supports dynamic generation of query statements at runtime.
Sample Code:
Criteria criteria = session. createCriteria (Customer. class); Criterion criterion1 = Expression. like ("namr", "T %"); Criterion criterion2 = Expression. eq ("age", new Integer (21); criteria = criteria. add (criterion1); criteria = criteria. add (criterion2); // execute the search List result = criteria. list (); // method chain programming style List result1 = session. createCriteria (Customer. class ). add (Expression. like ("namr" "T % ")). add (Expression . Eq ("age", new Integer (21). list (); Hibernate also provides the QBE (Qurey By Example) retrieval method, which is a sub-function of QBC. QBE allows you to create an on-demand template first, and then retrieve the same objects as this template. Sample Code: Customer exampleCustomer = new Customer (); exampleCustomer. setAge (21); List result1 = session. createCriteria (Customer. class ). add (Example. create (exampleCustomer )). list ();
HQL Retrieval Method
HQL (Hibernate Query Language) is an Object-Oriented Query Language, which is similar to the SQL Query Language. Among the various retrieval methods provided by Hibernate, HQL is the most widely used retrieval method. It has the following features:
Set various query conditions in the query statement.
Supports projection query, that is, only partial attributes of an object are retrieved.
Supports querying by page.
Supports group query and supports the group by and having keywords.
Provides built-in Aggregate functions, such as sum (), min (), and max ().
Can Call User-Defined SQL functions.
Supports subqueries, that is, nested queries.
Supports dynamic parameter binding.
The Qurey interface of the Session class supports HQL retrieval. It provides various query functions listed above.
Note: The Qurey interface supports the method chain programming style. Its set method returns its own instance instead of the void type. The method chain programming style makes the program code more concise.
Sample Code:
Query query = session. createQuery ("from Customer as c where" + "c. name =: customerName and c. age =: customerAge "); // dynamically binds the query parameter. setString ("customerName", "Test"); query. setInteger ("customerAge", 21); // execute the search List result = query. list (); // method chain programming style List result1 = session. createQuery ("from Customer as c where c. name =: customerName and c. age =: customerAge "). setString ("customerName", "Test "). setInteger ("customerAge", 21 ). list ();
5. Spring dependency injection (IOC) and Aspect-oriented programming (AOP)
Dependency injection: In layman's terms, service instances can be injected more flexibly to service users, without the need to instantiate service instances in advance. This greatly reduces the coupling between codes and achieves separation of code and functions. Service users, such as actions in SSH, only need to declare the service interface variables.
Or constructor operations (two injection methods) can be used to inject (instantiate) service objects ).
AOP: a plane is the implementation of an abstract function module. Generally speaking, it is the operation of each function implementation. A series of operations required to complete this function can be seen as one plane, aspect-Oriented Programming is to add other functions before or after this. It can be viewed as a functional module, such as the user login function and each client request operation.
Based on the different cut-in points, we can see that pre-notifications, post-notifications, intercept notifications, and exception notifications. The call of the first two notifications is before and after the cut plane, and the call of the latter two can be at the front and back of the cut plane.