没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
Struts2+ibatis+spring 整合开发
1. 工程结构图
2. 配置文件
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-
class>org.springframework.web.context.ContextLoaderListener</
listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-
class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
如图:
Struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration
2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.objectFactory.spring.autoWire"
value="type" />
<constant name="struts.objectFactory" value="spring" />
<include file="struts-default.xml"/>
<package name="struts2" extends="struts-default">
<default-interceptor-ref name="paramsPrepareParamsStack" />
<!-- aciton的class为applicationContext.xml中的注册名 -->
<action name="login" class="LoginAction">
<result name="success">/success.jsp</result>
<result name="input">/login.jsp</result>
</action>
<action name="save" class="LoginAction" method="save">
<result name="success" type="redirect-
action">show.action</result>
<result name="error">/error.jsp</result>
</action>
<action name="edit" class="LoginAction" method="edit">
<result name="success">update.jsp</result>
</action>
<action name="update" class="LoginAction" method="update">
<result name="success" type="redirect-
action">show.action</result>
<result name="error">/error.jsp</result>
</action>
<action name="delete" class="LoginAction" method="delete">
<result name="success" type="redirect-
action">show.action</result>
<result name="error">/error.jsp</result>
</action>
<action name="show" class="LoginAction" method="findAllUser">
<result name="success">/list.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
</struts>
如图:
Struts.properties
#struts.url.http.port=8080
struts.devMode=true
struts.configuration.xml.reload=true
struts.locale=zh_CN
struts.i18n.encoding=UTF-8
struts.objectFactory=spring
如图:
sql-map-config.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="cn/hsw/model/user.xml"/>
</sqlMapConfig>
如图:
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans default-autowire="byType"
xmlns="http://www.springframework.org/schema/beans"
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">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-
method="close">
<property name="driverClassName"
value="com.mysql.jdbc.Driver" />
<property name="url"
value="jdbc:mysql://127.0.0.1:3306/debug" />
<property name="username" value="root" />
<property name="password" value="123456" />
</bean>
<bean id="client"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="dataSource">
<ref local="dataSource"/>
</property>
<property name="configLocation">
<value>classpath:sql-map-config.xml</value>
</property>
</bean>
<!-- bean中的class为实现接口的类;property的name为类中引用的属性名称;
ref为spring注册的名称,如上面的client-->
<bean id="userDao"
class="cn.hsw.dao.UserDAO">
剩余28页未读,继续阅读
资源评论
- zi19882012-10-16初学ssi框架,马上要上项目,感谢楼主的分享
- aoxiang09272013-04-14非常好 基于了很大的帮助
xq856
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功