1. 创建web工程
2.创建包并加载Spring
步骤 :单击工程名----——MyEclipse-----Add Spring Capabilitiles-----
选择Spring version的(Spring1)并选择价包
( 1. Spring 1.2 Aop Librarues
2. Spring 1.2 Core Libraries
3. Spring 1.2 ORM/DAO/Hibernate3 Libraries
4. Spring 1.2 Web Libraries
)----点击Next
----- 把File重命名为:spring ---点击Finish
3.在MyEclipseDataSourse中配置好你所要用的数据源
4.加载Hibernate
步骤 :单击工程名----——MyEclipse-----Add Hibernate Capabilitiles----
选择Hibernate Specification的(Hibernate 3 )并选择价包
( 1. Hibernate 3.0 Core Libraries
2. Hibernate 3.0 Advanced Support Libraries
)
----点击Next----选择Spring configuration file----点击Next
----选择Existing Spring configuration file 把SessionFactory ID 起名:sessionfac
----点击Next-----
(
1.给Bean Id 起名:ds
2.DB Driver 选择刚才配置好的数据源名
)----- 点击Next ----Java package 选择(com.xaccp.util)---点击Finish
5.加载struts
6.生成实体类
步骤:1.在 MyEclipseDataSourse中选择你所需要的表----点击表----Hibernete Reverse Engineering
2.Java src folder 选择(com.xaccp.entity)
选择(
1.Hibernate mapping file
2.Update hiberbate configuration with mapping file location
3.Java Data Object 注意:不选择Create abstract class
4.Java Data Access Object(DAO) (Hibernate 3 only)
5.Generate precise findBy methods
)
----点击Next ---把ID Geberator 选择native---点击Next--
点击Users 把ID Generator选择(native)
选择Include referenced tables(A->B)
选择Include referenced tables(A <-B)
-----点击Finish---弹出对话框选择(NO)
7. 把entity包内的DAO移动到com.xaccp.dao并在spring文件中做相应的修改
8.自己写个类MyDelegatingRequestProcessor继承DelegatingRequestProcessor,重写processPreprocess,实现转码功能
例如:request.setCharacterEncoding("utf-8");
9.在Sturts-config-xml配置
在 <action-mappings /> 下配置: <controller processorClass="com.xaccp.util.MyDelegatingRequestProcessor"> </controller>
在 <message-resources parameter="com.xaccp.struts.ApplicationResources" />下配置插件
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="classpath:spring.xml"/>
</plug-in>
10.在spring.xml配置
1.生成htm 相当与生成Transaction
</bean >
<bean id="htm" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionfac"> </property>
</bean>
2. 把每个类的dao 注入到相应的所需的biz 注意:(biz的dao 必须具有set方法)
3. 创建事务
<bean id="basetarget" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="htm"> </property>
<property name="transactionAttributes">
<props>
<prop key="find*">PROPAGATION_REQUIRED,readOnly </prop>
<prop key="add*">PROPAGATION_REQUIRED </prop>
<prop key="upd*">PROPAGATION_REQUIRED </prop>
<prop key="del*">PROPAGATION_REQUIRED </prop>
</props>
</property>
</bean>
4.组装带事务的biz,让它里面的每个dao都具有事物
例如:
</bean>
<bean id="usebiz" parent="basetarget">
<property name="target" ref="stubiztarget"> </property>
</bean>
5.给action里的biz注入
<bean name="/stu" class="com.xaccp.struts.action.StuAction">
<property name="biz" ref="usebiz"> </property>
</bean>
ssh三大框架整合的简易步骤
最新推荐文章于 2024-06-14 10:17:52 发布