<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <!-- struts-config.xml--> <!--action的class属性需要改成代理类 org.springframework.web.struts.DelegatingActionProxy --> <action name="userForm" parameter="method" path="/user" scope="request" type="org.springframework.web.struts.DelegatingActionProxy" validate="false" /> <!--添加控制器和插件--> <controller> <set-property property="processorClass" value="org.springframework.web.struts.DelegatingRequestProcessor" /> </controller> <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"> <set-property property="contextConfigLocation" value="WEB-INF/applicationContext.xml" /> </plug-in> <!-- applicationContext.xml --> <!-- 把 Action 交给Spring管理--> <bean name="/user" class="yourcompany.yourprogram.action.UserAction"> <property name="biz" ref="userBiz"></property> </bean> <!-- 实体类映射关系 hbm.xml --> <!-- hibernate对应关系时注意添加 用户表:User 多个用户对应一个角色 角色表:Role 一个角色对应多个用户 --> <!-- many-to-one --> <!-- 添加 cascade="save-update" outer-join="auto" --> <many-to-one name="role" class="sw.role.entity.Role" fetch="select" cascade="save-update" outer-join="auto"> <column name="RoleId" not-null="true" /> </many-to-one> <!-- one-to-many --> <!-- 添加 inverse="false" cascade="all-delete-orphan" outer-join="true" --> <set name="user" inverse="false" cascade="all-delete-orphan" outer-join="true"> <key> <column name="RoleId" not-null="true" /> </key> <one-to-many class="sw.role.entity.Users" /> </set> </beans>