struts/spring/hibernate (SSH)
SSH Program Development Framework Setup process
Wen/Du Yi, Chen Union
2004.12.14 Goal: To build a struts+spring+hibernate MVC system Reference: Appfuse and the Internet circulated a very common set of SSH system. Installation steps:
1) Install Eclipse
2) Installation MyEclipse
3) Install Tomcat
4 Configuring Tomcat in Eclipse
5 copy Spring's required packages into/web-inf/lib
Overview of the overall structure
I. Configuration file
Two. Package structure
Three. The structure of the program is described in detail . configuration file
System profiles are common: Systems :
/web-inf/web.xml
Context-Environment listener
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Spring:
Under/web-inf A new folder named Spring-config is used to place the spring configuration file, and if struts is a multiple-configuration file, this is the recommended procedure.
/web-inf/spring-config/applicationcontext-resources.xml
/web-inf/spring-config/applicationcontext-hibernate.xml
/web-inf/spring-config/applicationcontext-service.xml
Struts
/web-inf/struts-config.xml
two. Package Structure
Com.yourdomain.appname.dao
Com.yourdomain.appname.dao.hibernate
Com.yourdomain.appname.model
Com.yourdomain.appname.service
Com.yourdomain.appname.service.impl
Com.yourdomain.appname.util
Com.yourdomain.appname.webapp
Com.yourdomain.appname.webapp.action
Com.yourdomain.appname.webapp.filter
Com.yourdomain.appname.webapp.form
Com.yourdomain.appname.webapp.listener
Com.yourdomain.appname.webapp.taglib
Com.yourdomain.appname.webapp.util
Three. Detailed description of the program structure (see framework examples) DAO Layer
General interface
Sub-interfaces inherit from the general interface
The total class inherits from
Org.springframework.orm.hibernate.support.HibernateDaoSupport
Simultaneous implementation of the total interface
Child classes inherit from the general class and implement sub-interfaces simultaneously
Manipulate the data model layer by Gethibernatetemplate () (provided by the parent class of the general Class Hibernatedaosupport)
General class implementation Serializable interface
Subclass implements General class and implements serializable interface service layer simultaneously
General interface Responsibilities
Child class Interface Independent
Total class implementation Total interface
Abstract method to invoke the DAO layer total class
protected DAO DAO = null;
Child classes inherit from the general class and implement sub-interfaces simultaneously
Specific ways to invoke the DAO layer subclass
Private Userdao DAO; Action Layer
General class implementation Org.apache.struts.action.Action
Own Getbean method
Subclass inherits from General class
This allows you to directly invoke the Getbean method of the parent class to obtain the manager of the service layer.
The code example is as follows:
Mytestusermanager mgr = (mytestusermanager) getbean ("Mytestusermanager"); String userId = "00001"; String userName = "XXX";C Mytestuser NewUser = new Mytestuser (); Newuser.setname (UserName); System.out.println (Newuser.getid ()); Mgr.savemytestuser (NewUser); R Mytestuser Mytestuser = Mgr.getmytestuser (userId); U Mytestuser UpdateUser = Mgr.getmytestuser (userId); Updateuser.setname (UserName); Mgr.savemytestuser (UpdateUser); D Mgr.removemytestuser (USERID); |