导入所有的包
在struts-config.xml中配置
修改action中type为:org.springframework.web.struts.DelegatingActionProxy
<action name="officeForm" path="/office" scope="request" parameter="method" type="org.springframework.web.struts.DelegatingActionProxy"> <forward name="showAll" path="/showgw.jsp"></forward> <forward name="addtest" path="/office.do?method=showAll"></forward> <forward name="edit" path="/editgw.jsp"></forward> </action>
在最后配置
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"> <set-property property="contextConfigLocation" value="classpath:applicationContext.xml" /> </plug-in>
applicationContext.xml配置
applicationContext.xml要放在src目录下,放在别的路径下要修改相应的路径
<!-- 配置一个数据源,根据location去找数据库连接的配置信息 --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property> <property name="url" value="jdbc:oracle:thin:@192.168.0.45:1521:orcl"/> <property name="username" value="shiqi"/> <property name="password" value="shiqi"/> </bean> <!-- 根据dataSource和configLocations创建一个SqlMapClient --> <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"> <property name="configLocations" value="classpath:com/zc/struts/ibatis/SqlMapConfig.xml"> <!--“classpath:com/zc/struts/ibatis/SqlMapConfig.xml”为SqlMapConfig.xm的路径--> </property> <property name="dataSource"> <ref bean="dataSource"/> </property> </bean> <!-- DAO层注入 --> <bean id="gwzfDao" class="com.zc.struts.dao.impl.GwzfDAOImpl"> <property name="sqlMapClient"> <ref bean="sqlMapClient"/> </property> <property name="dataSource"> <ref bean="dataSource"/> </property> </bean> <!-- Service层注入 --> <bean id="gwzfService" class="com.zc.struts.service.impl.GwzfServiceImpl"> <property name="gwzfDao" ref="gwzfDao"></property> </bean> <!-- 配置Action 控制bean --> <bean name="/office" class="com.zc.struts.action.OfficeAction"> <property name="gwzfService" ref="gwzfService"></property> </bean>
SqlMapConfig.xml
中的内容为:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-config-2.dtd"> <sqlMapConfig> <sqlMap resource="com/zc/struts/ibatis/Gwzf.xml"/> </sqlMapConfig>
另一个 ibatis xml 中的内容为:主要写的是 sql语句
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd"> <sqlMap namespace="GongWen"> <typeAlias alias="Gwzf" type="com.zc.struts.pojo.Gwzf"/> <resultMap id="GwzfRs" class="Gwzf"> <result property="file_id" column="FILE_ID"/> <result property="file_title" column="FILE_TITLE"/> <result property="file_date" column="FILE_DATE"/> <result property="file_wh" column="FILE_WH"/> <result property="file_wh_dw" column="FILE_WH_DW"/> <result property="file_wh_year" column="FILE_WH_YEAR"/> <result property="file_wh_number" column="FILE_WH_NUMBER"/> <result property="file_people_name" column="FILE_PEOPLE_NAME"/> </resultMap> <resultMap id="Gwzfid" class="Gwzf"> <result property="file_id" column="FILE_ID"/> </resultMap> <select id="selectAllGw" resultMap="GwzfRs">select * from FILEMANAGER_HZC</select> <select id="selectById" parameterClass="String" resultMap="GwzfRs"> select * from FILEMANAGER_HZC where FILE_ID = #file_id# </select> <insert id="insertGw" parameterClass="Gwzf"> insert into FILEMANAGER_HZC(FILE_ID,FILE_TITLE,FILE_DATE,FILE_WH,FILE_WH_DW,FILE_WH_YEAR,FILE_WH_NUMBER,FILE_PEOPLE_NAME) values( HZC_FILEMANAGER.NEXTVAL,#file_title#,#file_date#,#file_wh#,#file_wh_dw#,#file_wh_year#,#file_wh_number#,#file_people_name#) </insert> <update id="updateGwzf" parameterClass="Gwzf"> update FILEMANAGER_HZC set FILE_TITLE = #file_title#, FILE_DATE = #file_date#, FILE_WH = #file_wh#, FILE_WH_DW = #file_wh_dw#, FILE_WH_YEAR = #file_wh_year#, FILE_WH_NUMBER = #file_wh_number#, FILE_PEOPLE_NAME = #file_people_name# where FILE_ID = #file_id# </update> <delete id="deleteGwById" parameterClass="String"> delete from FILEMANAGER_HZC where FILE_ID = #id# </delete> <!-- 检测文号 --> <select id="checkwh" parameterClass="String" resultMap="Gwzfid"> select FILE_ID from FILEMANAGER_HZC where FILE_WH=#filewh# </select> </sqlMap>