Struts + Spring +ibatis 整合开发步骤
来源:互联网 发布:python重定向到文件 编辑:程序博客网 时间:2024/06/01 09:10
一.添加Spring 、Struts框架对web.xml文件的修改
1. 添加Spring框架
2. 在web.xml中引入Spring配置文件(注意:applicationContext.xml文件的路径)
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/conf/applicationContext.xml
</param-value>
</context-param>
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
3. 添加Struts框架
4. 在web.xml中引入Struts配置文件(注意:struts-config.xml文件的路径)
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/conf/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
5. web.xml自动添加的*.jsp文件起始路径(注意:jsp文件的访问路径)
<welcome-file-list>
<welcome-file>/WEB-INF/jsp/emp.jsp</welcome-file>
</welcome-file-list>
二、对Spring配置文件applicationContext.xml文件的修改
1. 配置JDBC数据源驱动文件 jdbc.properties(服务器、端口、账户、密码因具体情况而定)
MySql:
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test
jdbc.username=root
jdbc.password=admin
Oracle:
jdbc.driver=oracle.jdbc.driver.OracleDriver
jdbc.url=jdbc:oracle:thin:@127.0.0.1:1521:orcl
jdbc.username=scott
jdbc.password=tiger
MS Sql Server:
jdbc.driver= com.microsoft.jdbc.sqlserver.SQLServerDriver
jdbc.url= jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mssql
jdbc.username=sa
jdbc.password=sa
2. 将JDBC驱动源文件部署到ApplicationContext.xml配置文件中
<beanid="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<propertyname="locations">
<list>
<value>/WEB-INF/conf/jdbc.properties</value>
</list>
</property>
</bean>
3. 将Data Source配置到ApplicationContext文件中
<beanid="dataSource"class="org.apache.commons.dbcp.BasicDataSource"destroy-method="close">
<propertyname="driverClassName">
<value>${jdbc.driver}</value>
</property>
<propertyname="url">
<value>${jdbc.url}</value>
</property>
<propertyname="username">
<value>${jdbc.username}</value>
</property>
<propertyname="password">
<value>${jdbc.password}</value>
</property>
<propertyname="minIdle">
<value>1</value>
</property>
<propertyname="maxActive">
<value>25</value>
</property>
<propertyname="maxIdle">
<value>5</value>
</property>
</bean>
4. 在Spring配置中注入3中的datasource数据源
<beanid="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<propertyname="dataSource">
<reflocal="dataSource"/>
</property>
</bean>
5. 引入具体的sql语句配置文件(注意:sqlMapConfig.xml文件的路径)
<beanid="sqlMapClient"class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<propertyname="configLocation">
<value>/WEB-INF/conf/sqlMapConfig.xml</value>
</property>
<propertyname="dataSource">
<reflocal="dataSource"/>
</property>
</bean>
6. 注入操作数据库的dao(empDao是举例)
<beanid="empDao"class="com.web.ssi.emp.dao.EmpDaoImpl">
<propertyname="sqlMapClient">
<reflocal="sqlMapClient"/>
</property>
</bean>
三. 对Struts配置文件struts-config.xml文件的修改
1. 填写form-bean
<form-beans>
<form-beanname="empForm"type="com.web.ssi.emp.form.EmpForm"/>
</form-beans>
2. 填写action-mapping
<action-mappings>
<action
name="empForm"
path="/queryEmp"
type="org.springframework.web.struts.DelegatingActionProxy"
scope="request">
<forwardname="queryEmp"path="/jsp/emp.jsp"/>
</action>
</action-mappings>
3. 填写message-resource 和plug-in(注意:action-servlet.xml文件路径)
<message-resourcesparameter="com.web.ssi.ApplicationResources"/>
<plug-inclassName="org.springframework.web.struts.ContextLoaderPlugIn">
<set-propertyproperty="contextConfigLocation"value="/conf/applicationContext.xml"/>
</plug-in>
4. Spring与Struts相对用的配置applicationContext.xml
<beans>
<beanname="/queryEmp"class="com.web.ssi.emp.action.EmpAction"singleton="false">
<propertyname="empService">
<refbean="empService"/>
</property>
</bean>
</beans>
附一:配置文件示意图如下
附二:包结构
- Struts + Spring +ibatis 整合开发步骤:
- Struts + Spring +ibatis 整合开发步骤
- Struts + Spring +ibatis 整合开发步骤
- Struts + Spring +ibatis 整合开发步骤
- Struts + Spring +ibatis 整合开发步骤
- Struts + Spring +ibatis 整合开发步骤
- spring,struts,整合后整合iBATIS
- Spring+Struts+Hibernate整合步骤
- struts+spring+ibatis+velocity整合配置
- SSI(Struts,Spring,Ibatis)整合总结
- ibatis+spring+struts整合应用实例
- ibatis+spring+struts整合实例【好例子】
- 对struts,ibatis,spring的整合
- ibatis+spring+struts整合应用实例
- ibatis+spring+struts整合应用实例
- ibatis+spring+struts整合应用实例
- Spring+Ibatis整合开发实例
- Spring整合ibatis开发配置
- 以写模式来运行orion,会损坏asm 磁盘组
- jQuery相关知识
- ST发飙,8-Pin MCU来袭! STM8S001 ( STM8S001J3M3 )即将登场!
- 程序员对谷歌、百度正确的使用方法
- 分割句子
- Struts + Spring +ibatis 整合开发步骤
- 使用intelliJ IDEA 2017 for mac 编写jsp文件且在java文件中链接MySQL数据库的问题
- Android Kotlin
- 剑指offer--面试题12:矩阵中的路径
- 中兴新支点Linux桌面操作系统初次使用体验
- 基于深度学习的验证码自动识别(caffe)
- [LeetCode] 566. Reshape the Matrix
- 20170711考试总结
- Redis-Bitmaps应用