"SSH"---"Struts2, Hibernate5, Spring4" "SSH Framework Integration Notes"

Source: Internet
Author: User

Why should I use an interface?

Three-tier architecture it is best to use an interface when the upper layer is called, such as when the action layer invokes the service, private Iuserdao Userdao, where the attribute is defined as an interface, and when the DAO is called, it is the method that invokes the interface. The realization of this interface class has a lot of implementation methods, both can be implemented with hibernate, but also with the implementation of JDBC, so in the application can easily switch, greatly improving the flexibility of the program.

Second, hibernate working principle and why use?

Principle:
1. Through the configuration (). Configure (); Read and parse the Hibernate.cfg.xml config file
2. Read and parse the mapping information by <mapping resource= "Com/xx/user.hbm.xml"/> in Hibernate.cfg.xml
3. Through Config.buildsessionfactory ();//Create Sessionfactory
4.sessionfactory.opensession ();//Open Sesssion
5.session.begintransaction ();//Create Transaction Transation
6.persistent operate persistent operation
7.session.gettransaction (). commit ();//COMMIT Transaction
8. Close session
9. Close Sesstionfactory

Why to use:
1. The code for JDBC access to the database is encapsulated, which greatly simplifies the tedious repetitive code of the data access layer.

2. Hibernate is a JDBC-based, mainstream persistence framework that is an excellent ORM implementation. He simplifies the coding of the DAO layer to a great extent

3. Hibernate uses the Java reflection mechanism rather than the bytecode enhancer to achieve transparency.

4. Hibernate performs very well because it is a lightweight framework. The flexibility of the mapping is excellent. It supports a variety of relational databases, from one-to-one to many-to-many complex relationships.

Reference Learning

Third, the implementation process of STRUTS2

The basic brief flow is as follows:

1. The client browser makes an HTTP request.

2, according to the Web. XML configuration, the request was Filterdispatcher received.

3, according to the Struts.xml configuration, find the action class and method that need to be called, and through the IOC way, the value is injected to Aciton.

4. Action invokes the business logic component to process the business logic, which includes form validation.

5, the action is completed, according to the configuration in the Struts.xml to find the corresponding result of the return, and jump to the corresponding page.

6. Returns the HTTP response to the client browser.

Reference Learning

Why to use:
The advent of JSP, Servlet, and JavaBean technology gives us the possibility to build powerful enterprise application systems. But the systems built with these techniques are very fanluan, so on top of that, we need a rule, a rule that organizes these technologies, and that is the framework in which struts emerges.

Struts-based applications consist of 3 types of components: Model components, view components, controller components

MVC design Pattern:
Modal: "Model" is also called business logic, is really the code to complete the task, quite with JavaBean
View: is actually the display interface, the equivalent of JSP
Controller: Controllers, he controls the interaction of models and views, equivalent to Servlet

Reference source http://blog.csdn.net/alli0968/article/details/4231237

"SSH"---"Struts2, Hibernate5, Spring4" "SSH Framework Integration Notes"

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.