Quick Start
This article is a primer for developing Web applications based on spring, using the Struts MVC framework, the middle tier using spring, and the background using hibernate.
This article contains the following elements:
• Configure Hibernate and transactions
• Load Spring's applicationcontext.xml file
• Establish dependencies between the business layer and the DAO
• Apply spring to Struts
Overview cable
This example is the establishment of a simple Web application called Myusers, complete user management operations, including simple database add, delete, check, that is crud (new, Access, update, delete) operations. This is a three-tier Web application that accesses the business layer through action (Struts), and the business layer accesses the DAO. Figure I briefly describes the overall structure of the application. The figures on the diagram illustrate the sequence of processes-from the web (useraction) to the middle tier (Usermanager), to the data Access layer (USERDAO), and then return the results.
The real strength of the spring layer is its declarative transactions, the support and persistence layer (e.g. hiberate and Ibatis)
Below is the steps to complete this example:
1. Install Eclipse plug-in
2. Database Build Table
3. Configuring Hibernate and Spring
4. Build the implementation class for the Hibernate DAO interface
5. Run the test class to test the DAO's CRUD operations
6. Create a processing class that declares a transaction
7. Create the action and model for the Web layer
8. Test class to run action test CRUD operations
9. Create a JSP file for CRUD operations through the browser
2. Spring Plugin http://springframework.sourceforge.net/spring-ide/eclipse/updatesite/
3. MyEclipse plugin (cracked version)
4. Tomcat plug-in. Tanghan
5. Other plug-ins include xml,jsp,
Database CREATE table App_user (ID number not NULL primary,firstname Vchar (), LastName Vchar (32)); New project
Create a new Web project,
The new directory structure, as shown in the previous illustration, also contains the new Folder page for the JSP file, and the source folder test for the JUnit test file. The packages that are used at the same time, including struts,hibernate,spring, are imported into the Lib directory.
Create a persistent layer O/R mapping
1. Export App_user. hbm.xml file from the database with the Hibernate plugin under Src/com.jandar.model renamed to User.hbm.xml
2. User.java files are generated by Hibernate Synchronizer->synchronizer file, and the user object corresponds to the App_user table in the database
Note: Automatically generated object files are not exactly the same under Eclipse, the same is that each object file must implement the Serializable interface, both ToString and Hashcode methods;
The method of Iuserdao interface is implemented in this class, and the Hibernatedaosupport class is inherited. The role of this class is to access, manipulate objects through hibernate, and then implement the operation of the database.
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.