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. ssh-add - 向认证代理添加 RSA 或 DSA 身份数据

    总览 (SYNOPSIS) ssh-add [-lLdDx ] [-t life ] [file ... ] ssh-add -s reader ssh-add -e reader 描述 (DESCR ...

  2. 一、WebApi模型验证实践项目使用

    一.启语 前面我们说到,模型验证的原理(包含1.项目创建,2.模型创建,3.走通测试模型验证,4.在过滤器中处理返回json格式(非控制器内))-完全是新手理解使用的,新番理解 通常情况下,对于那些经 ...

  3. Java虚拟机(JVM)与垃圾回收机制(GC)的详解

    一.JVM结构 根据<java虚拟机规范>规定,JVM的基本结构一般如下图所示: 从左图可知,JVM主要包括四个部分: 1.类加载器(ClassLoader):在JVM启动时或者在类运行时 ...

  4. Center os vi

    vi /etc/virc set nu 设置所有文件显示行号 :1,$s/after/befer/g  全局替换 :%s/after/befer/g 全局替换 yy 复制一行 p 粘贴 yw 复制一个 ...

  5. spring boot集成mongodb的增删改查

    添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>sp ...

  6. BZOJ5415 [NOI2018] 归程

    今天也要踏上归程了呢~(题外话 kruskal重构树!当时就听学长们说过是重构树辣所以做起来也很快233 就是我们按照a建最大生成树 这样话呢我们就可以通过生成树走到尽量多的点啦 然后呢就是从这个子树 ...

  7. 爬虫技术:scrapy 知识点一

    ---恢复内容开始--- 1.scrapy框架 每一步的解释: step1:引擎从爬虫器获取要爬行的初始请求. step2:引擎在调度程序中调度请求,引擎把这个初始请求传递给调度器,并向调度器索要下一 ...

  8. kali网络源配置

    使用vim对sources.list文件进行修改: $   vim /etc/apt/sources.list 随便挑选一个源添加到该文件中 ----------------------------- ...

  9. python在windows中运行文件

    "d:Program Files\python35\python.exe" hello.txt

  10. boost number handling

    Boost.Integer defines specialized for integers. 1. types for integers with number of bits #include & ...