User.xml

<?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="user"> <!-- Use type aliases to avoid typing the full classname every time. -->
<typeAlias alias="User" type="******.beans.User"/> <!-- Result maps describe the mapping between the columns returned
from a query, and the class properties. A result map isn't
necessary if the columns (or aliases) match to the properties
exactly. -->
<resultMap id="UserResult" class="User">
<result property="userName" column="name"/>
<result property="password" column="password"/>
</resultMap> <!-- Select with no parameters using the result map for Account class. -->
<select id="selectAllUser" resultMap="UserResult">
select * from User
</select> <!-- A simpler select example without the result map. Note the
aliases to match the properties of the target result class. -->
<select id="selectUserByName" parameterClass="java.lang.String" resultClass="User">
select
name as userName,
password as password
from user
where name = #userName#
</select> <!-- Insert example, using the User parameter class-->
<insert id="insertUser" parameterClass="User">
insert into User (
name,
password )
values (#userName#,#password#)
</insert> <!-- Update example, using the Account parameter class
<update id="updateAccount" parameterClass="Account">
update ACCOUNT set
ACC_FIRST_NAME = #firstName#,
ACC_LAST_NAME = #lastName#,
ACC_EMAIL = #emailAddress#
where
ACC_ID = #id#
</update>
-->
<!-- Delete example, using an integer as the parameter class
<delete id="deleteAccountById" parameterClass="int">
delete from ACCOUNT where ACC_ID = #id#
</delete>
-->
</sqlMap>

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> <!-- The properties (name=value) in the file specified here can be used
placeholders in this config file (e.g. “${driver}”. The file is relative
to the classpath and is completely optional.
<properties resource="db.properties" /> --> <!-- These settings control SqlMapClient configuration details, primarily
to do with transaction management. They are all optional (more detail
later in this document).
<settings
cacheModelsEnabled="true"
enhancementEnabled="true"
lazyLoadingEnabled="true"
maxRequests="32"
maxSessions="10"
maxTransactions="5"
useStatementNamespaces="false"/> --> <!-- Configure a built-in transaction manager. If you're using an
app server, you probably want to use its transaction manager
and a managed datasource <transactionManager type="JDBC" commitRequired="false">
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="${driver}"/>
<property name="JDBC.ConnectionURL" value="${url}"/>
<property name="JDBC.Username" value="${username}"/>
<property name="JDBC.Password" value="${password}"/>
<property name="JDBC.DefaultAutoCommit" value="true" />
<property name="Pool.MaximumActiveConnections" value="10"/>
<property name="Pool.MaximumIdleConnections" value="5"/>
<property name="Pool.MaximumCheckoutTime" value="120000"/>
<property name="Pool.TimeToWait" value="500"/>
<property name="Pool.PingQuery" value="select 1 from User"/>
<property name="Pool.PingEnabled" value="false"/>
<property name="Pool.PingConnectionsOlderThan" value="1"/>
<property name="Pool.PingConnectionsNotUsedFor" value="1"/>
</dataSource>
</transactionManager> --> <!-- List the SQL Map XML files. They can be loaded from the classpath, as they are here (com.domain.data...) -->
<!-- List more here...
<sqlMap resource="com/mydomain/data/Order.xml"/>
<sqlMap resource="com/mydomain/data/Documents.xml"/>
-->
<sqlMap resource="*********/User.xml"/> </sqlMapConfig>

beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:property-placeholder location="classpath:db.properties"/>
<context:annotation-config/>
<context:component-scan base-package="com.****"/>
<!--此bean用来告诉Spring去何处找数据库信息,有此Bean才会有下面dataSource中用${}标记来取变量的语句
<bean id="propertyConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:db.properties</value>
</property>
</bean>
-->
<!--配置一个数据源,根据上面propertyConfig指定的location去找数据库连接的配置信息 -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>${driver}</value>
</property>
<property name="url">
<value>${url}</value>
</property>
<property name="username">
<value>${username}</value>
</property>
<property name="password">
<value>${password}</value>
</property>
</bean> <!--根据dataSource和configLocation创建一个SqlMapClient -->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocations">
<list>
<!-- sql语句配置xml文件 -->
<value>classpath:SqlMapConfig.xml</value>
</list>
</property>
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean> <!--根据sqlMapClien创建一个sqlMapClientTemplate模版类 -->
<bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClient">
<ref bean="sqlMapClient" />
</property>
</bean>
</beans>

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd"> <struts>
<!--
以下指定了对象工厂为StrutsSpringObjectFactory,这样struts2的action就不再又
struts2而是由spring负责产生了,另外action元素中的class属性不再指向其实际的class,
而是指向beans.xml中某个action bean的id
-->
<constant name="struts.objectFactory" value="org.apache.struts2.spring.StrutsSpringObjectFactory" />
<!--
<constant name="struts.objectFactory" value="spring" />
-->
<constant name="struts.devMode" value="true" />
<constant name="struts.enable.DynamicMethodInvocation" value="false" /> <package name="default" namespace="/" extends="struts-default">
<action name="save" class="userAction" method="userAdd">
<result name="sucess">/sucess.jsp</result>
<result name="failure">/failure.jsp</result>
</action>
</package>
<!--
<package name="default" namespace="/" extends="struts-default">
<default-action-ref name="index" />
<global-results>
<result name="error">/error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="error"/>
</global-exception-mappings>
<action name="index">
<result type="redirectAction">
<param name="actionName">HelloWorld</param>
<param name="namespace">/example</param>
</result>
</action>
</package>
<include file="example.xml"/>
--> <!-- Add packages here --> </struts>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-- 配置Spring监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- 用来定位Spring XML文件的上下文配置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:beans.xml</param-value>
</context-param> <!-- 配置struts2 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter> <filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<!-- 记住加入这个配置,不然在使用struts-tag标签会报错误 -->
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
//     ActionContext context = ActionContext.getContext();
// Map request = (Map) context.get("request");
// Map session = context.getSession();
// Map application = context.getApplication();
// // 在请求中放置欢迎信息。
// request.put("greeting", "欢迎您来到程序员之家");
// // 在session中保存password属性
// session.put("password", "111111"); // 通过接口注入来获取request、session和application对象的LoginAction:
//RequestAware
//SessionAware
//ApplicationAware HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session = request.getSession();
ServletContext context = ServletActionContext.getServletContext(); // 在请求中放置欢迎信息。
request.setAttribute("greeting", "欢迎您来到程序员之家");
// 在session中保存user对象
session.setAttribute("password", "111111");

spring3.0+struts2+ibatis整合的更多相关文章

  1. spring3.0+jsf+ibatis整合

    user.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE sqlMap PUBLI ...

  2. 开发基础框架:mybatis-3.2.8 +hibernate4.0+spring3.0+struts2.3

    一:项目下载地址(点击 Source code(zip)) https://github.com/fzxblgong/frame_2014-12-15/releases 版本:v1.2大小:20M 二 ...

  3. MyEclipse-10.0下Struts2.1+Spring3.0+Hibernate3.3整合过程

    新建web project: 命名为SSH,做如下设置: 新建后的工程目录如下: 然后开始添加SSH框架,这里我按照struts-spring-hibernate顺序进行添加. 首先添加struts2 ...

  4. Struts2.1.8 + Spring3.0+ Hibernate3.2整合笔记

    body, p, th, td, li, ul, ol, h1, h2, h3, h4, h5, h6, pre { font-family: simsun; line-height: 1.4; } ...

  5. Spring4.0+Hibernate4.0+Struts2.3整合包括增删改查案例,解决整合中出现的异常

    源码下载:http://download.csdn.net/detail/cmcc_1234/7034775 ======================Application.xml======== ...

  6. Maven整合Spring3.0+Mybatis3.2+Struts2.3+查找坐标+jar包依赖(五)

    依赖传递 只添加了一个struts2-core依赖,发现项目中出现了很多jar,这种情况 叫 依赖传递

  7. Jbpm4.4+hibernate3.5.4+spring3.0.4+struts2.1.8整合例子(附完整的请假流程例子,jbpm基础,常见问题解决)

    Jbpm4.4+hibernate3.5.4+spring3.0.4+struts2.1.8 整合例子(附完整的请假流程例子). 1.jbpm4.4 测试环境搭建 2.Jbpm4.4+hibernat ...

  8. Jbpm4.4+hibernate3.5.4+spring3.0.4+struts2.1.8 整合例子

    转自:http://www.blogjava.net/wangxinsh55/archive/2011/07/24/354925.html   Jbpm4.4+hibernate3.5.4+sprin ...

  9. SSH (Struts2+Spring3.0+Hibernate3)框架(二) 框架的配置

    一.准备工作: 1. JDK -> jdk1.6.0_17 安装(环境变量配置): JAVA_HOME = C:\ jdk1.6.0_17; PATH = %JAVA_HOME%\bin; %J ...

随机推荐

  1. Java 集合遍历

    在集合中使用Lambda表达式 Map集合中 forEach and Map 常规遍历-> 两种遍历: Map map = new HashMap(); map.put(102, "张 ...

  2. linux处理器子系统调优

  3. 阿里云搭建香港代理服务器 shadownsocks

    阿里云香港代理服务器搭建方式: 1.阿里云官网购买轻量级服务器即可,流量,配置套餐自己选择,CENTOS7,进入控制台后打开端口管理列表,打开9000即可. 2.安装shadownsocks服务端: ...

  4. 灰常牛逼的命令行备忘录 navi

    灰常牛逼的命令行备忘录 navi 1. navi命令简介 1.1 navi命令简介 命令行是非常高效的工具,但一个很常见的现象是,很多命令行过一段时间就容易忘.举个栗子,如果我们常用 git 命令行管 ...

  5. java两个引用指向同一个对象

  6. 「校内训练 2019-04-23」越野赛车问题 动态dp+树的直径

    题目传送门 http://192.168.21.187/problem/1236 http://47.100.137.146/problem/1236 题解 题目中要求的显然是那个状态下的直径嘛. 所 ...

  7. pgsql SQL监控,查询SQL执行情况

    SELECT procpid, START, now() - START AS lap, current_query FROM ( SELECT backendid, pg_stat_get_back ...

  8. boost compressedPair

    boost::compressed_pair behaves like std::pair. However, if one or both template parameters are empty ...

  9. 为你的AliOS Things应用增加自定义cli命令

    摘要: 怎么才能在RTOS系统中,通过 串口shell控制LED的开关. 在日常嵌入式开发中,我们经常会用串口命令来使设备进入某种特定的状态,或执行某个特定的操作.如系统自检,模拟运行,或者进入手动模 ...

  10. temp = yield i 这句话的意思?

    def test(): i = 0 while i < 5: temp = yield i # print(temp) i+=1 t = test() print(t.__next__()) p ...