文章来源:IT工程信息网http://www.systhinker.com/?action-viewnews-itemid-17500
1:创建数据库并把表创建好
2:开启MyEclipse,利用MyEclipse的数据库浏览创建一个数据库连接,连接目标是在第一步创建的数据库
3:创建考试的web工程
4:添加struts支持,同时删除struts的支持库
5:添加spring支持(不勾选支持库),打开applicationContext.xml,删除所有代码替换里面的内容如下:

< beans xmlns = " http://www.springframework.org/schema/beans "
xmlns:tx = " http://www.springframework.org/schema/tx "
xmlns:xsi = " http://www.w3.org/2001/XMLSchema-instance "
xsi:schemaLocation = " http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http: // www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
" >
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" autowire="byName"/>
<tx:annotation-driven transaction-manager="txManager"/>
</beans>
6:添加hibernate支持(不勾选支持库),数据库选择我们第二步建立的名字
7:打开/WEB-INF/struts-config.xml,在<action-mappings />后面一行加入一行代码
8:打开/WEB-INF/web.xml,加入如下代码(注意,如果你用的是GBK编码格式则将里面的UTF-8修改为GBK既可,其他地方不用变):

< param - name > contextConfigLocation </ param - name >
< param - value >
classpath:applicationContext.xml
</ param - value >
</ context - param >
< listener >
< listener - class >
org.springframework.web.context.ContextLoaderListener
</ listener - class >
</ listener >
< filter >
< filter - name > OpenSessionInViewFilter </ filter - name >
< filter - class >
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</ filter - class >
< init - param >
< param - name > singleSession </ param - name >
< param - value > true </ param - value >
</ init - param >
< init - param >
< param - name > flashMode </ param - name >
< param - value > COMMIT </ param - value >
</ init - param >
</ filter >
< filter - mapping >
< filter - name > OpenSessionInViewFilter </ filter - name >
< url - pattern > /* </url-pattern>
</filter-mapping>
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
9:将SSH的包导入工程或者将里面的jar文件拷贝到/WEB-INF/lib目录下,两者选其一。
10:反转数据库表为实体类(列实体类名称为Mods),(如果不清楚可以如此操作:打开Myeclipse的数据库浏览器窗口,打开第二步创建的连接,打开后进入到dbo目录下的table目录,右击创建好的表选择Hibernate reverse engining)
11:创建实体类的DAO接口,并包含如下四个方法
void add(Mods mods);
void del(Integer id);
void update(Mods mods);
Mods get(Integer id);
List loadAll();
12:实现Dao接口,这个实现类必须继承HibernateDaoSupport并在spring配置文件中注册此类
13:创建业务接口并实现,类上面加入一个注记@Transactional(rollbackFor={Exception.class})
14:创建Action,此Action继承DispatchAction,并在spring注册此类
15:编写页面并修改action
测试并完成!