`
yuanfen860913
  • 浏览: 119772 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

ibatis3整合spring

阅读更多

因为ibatis3现在还是测试版,spring也没有出相应的整合。所以,我根据spring整合hibernate的原理,也出来show一下,高手就不要笑我了。开工

主要是的文件有:
Ibatis3SessionFactory.java 这个是由spring读取ibatis配置文件,并产生sessionFactory工厂的

Ibatis3DaoSupport.java 我们的dao主要继承它了,因为它有一个模板类,定义了许多方法.

IBatis3DaoTemplate.java 不是上面的说的模板类

SqlSessionCallback.java 回调方法。

一 . 我们先来看一下Ibatis3SessionFactory.java

Java代码
package com.ibatis3;

import java.io.IOException;
import java.io.Reader;

import javax.sql.DataSource;

import org.apache.ibatis.builder.xml.XMLConfigBuilder;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.mapping.Environment;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.defaults.DefaultSqlSessionFactory;
import org.apache.ibatis.transaction.managed.ManagedTransactionFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;
/*
* session工厂类
*/
public class Ibatis3SessionFactory implements FactoryBean, InitializingBean {
private String configLocation;

private DataSource dataSource;

private SqlSessionFactory sqlSessionFactory;

private boolean useTransactionAwareDataSource = true;

private String environmentId = "development";

public void setEnvironmentId(String environmentId) {
this.environmentId = environmentId;
}

public void setUseTransactionAwareDataSource(
boolean useTransactionAwareDataSource) {
this.useTransactionAwareDataSource = useTransactionAwareDataSource;
}

public Object getObject() throws Exception {
return this.sqlSessionFactory;
}

public Class getObjectType() {
return (this.sqlSessionFactory != null ? this.sqlSessionFactory
.getClass() : SqlSessionFactory.class);
}

public boolean isSingleton() {
return true;
}

public void afterPropertiesSet() throws Exception {
this.sqlSessionFactory = this.buildSqlSessionFactory(configLocation);
}
protected SqlSessionFactory buildSqlSessionFactory(String configLocation)
throws IOException {
if (configLocation == null) {
throw new IllegalArgumentException(
"configLocation entry is required");
}
DataSource dataSourceToUse = this.dataSource;
if (this.useTransactionAwareDataSource
&& !(this.dataSource instanceof TransactionAwareDataSourceProxy)) {
dataSourceToUse = new TransactionAwareDataSourceProxy(
this.dataSource);
}

Environment environment = new Environment(environmentId,
new ManagedTransactionFactory(), dataSourceToUse);

Reader reader = Resources.getResourceAsReader(configLocation);
XMLConfigBuilder parser = new XMLConfigBuilder(reader, null, null);
Configuration config = parser.parse();
config.setEnvironment(environment);

return new DefaultSqlSessionFactory(config);
}

public DataSource getDataSource() {
return dataSource;
}

public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}

public void setConfigLocation(String configLocation) {
this.configLocation = configLocation;
}
}
package com.ibatis3;

import java.io.IOException;
import java.io.Reader;

import javax.sql.DataSource;

import org.apache.ibatis.builder.xml.XMLConfigBuilder;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.mapping.Environment;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.defaults.DefaultSqlSessionFactory;
import org.apache.ibatis.transaction.managed.ManagedTransactionFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;
/*
* session工厂类
*/
public class Ibatis3SessionFactory implements FactoryBean, InitializingBean {
private String configLocation;

private DataSource dataSource;

private SqlSessionFactory sqlSessionFactory;

private boolean useTransactionAwareDataSource = true;

private String environmentId = "development";

public void setEnvironmentId(String environmentId) {
this.environmentId = environmentId;
}

public void setUseTransactionAwareDataSource(
boolean useTransactionAwareDataSource) {
this.useTransactionAwareDataSource = useTransactionAwareDataSource;
}

public Object getObject() throws Exception {
return this.sqlSessionFactory;
}

public Class getObjectType() {
return (this.sqlSessionFactory != null ? this.sqlSessionFactory
.getClass() : SqlSessionFactory.class);
}

public boolean isSingleton() {
return true;
}

public void afterPropertiesSet() throws Exception {
this.sqlSessionFactory = this.buildSqlSessionFactory(configLocation);
}
protected SqlSessionFactory buildSqlSessionFactory(String configLocation)
throws IOException {
if (configLocation == null) {
throw new IllegalArgumentException(
"configLocation entry is required");
}
DataSource dataSourceToUse = this.dataSource;
if (this.useTransactionAwareDataSource
&& !(this.dataSource instanceof TransactionAwareDataSourceProxy)) {
dataSourceToUse = new TransactionAwareDataSourceProxy(
this.dataSource);
}

Environment environment = new Environment(environmentId,
new ManagedTransactionFactory(), dataSourceToUse);

Reader reader = Resources.getResourceAsReader(configLocation);
XMLConfigBuilder parser = new XMLConfigBuilder(reader, null, null);
Configuration config = parser.parse();
config.setEnvironment(environment);

return new DefaultSqlSessionFactory(config);
}

public DataSource getDataSource() {
return dataSource;
}

public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}

public void setConfigLocation(String configLocation) {
this.configLocation = configLocation;
}
}

上面代码也借鉴了网络上部分代码,因为转来转去,也不知谁是原创。

二. 下面是最简单的回调函数:

Java代码
package com.ibatis3;

import org.apache.ibatis.session.SqlSession;

public interface SqlSessionCallback {
public Object doInSqlSession(SqlSession session);
}
package com.ibatis3;

import org.apache.ibatis.session.SqlSession;

public interface SqlSessionCallback {
public Object doInSqlSession(SqlSession session);
}


三.模板类

Java代码
package com.ibatis3;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import javax.sql.DataSource;

import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.taglibs.standard.tag.common.sql.DataSourceUtil;
import org.springframework.jdbc.datasource.DataSourceUtils;
import org.springframework.jdbc.support.JdbcAccessor;
import org.springframework.transaction.support.TransactionSynchronizationManager;

public class IBatis3DaoTemplate extends JdbcAccessor {
private SqlSessionFactory sessionFactory;

public IBatis3DaoTemplate(SqlSessionFactory factory) {
this.sessionFactory = factory;
}

public SqlSession openSession() {
SqlSession session = (SqlSession) TransactionSynchronizationManager
.getResource(sessionFactory);
if (session == null) {
session = sessionFactory.openSession();
}
return session;
}

public void setSessionFactory(SqlSessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}

public List executeFind(SqlSessionCallback callback) {
return (List) execute(callback);
}

public Object execute(SqlSessionCallback callback) {

SqlSession session = openSession();

Object obj = callback.doInSqlSession(session);
if (session != null)
session.close();

return obj;
}

// 删除,根据语句
public int delete(final String statement) {
return delete(statement, null);
}

// 删除,根据语句,带条件
public int delete(final String statement, final Object param) {
return (Integer) execute(new SqlSessionCallback() {

public Object doInSqlSession(SqlSession session) {
if (param != null)
return session.delete(statement, param);
else
return session.delete(statement);
}
});
}

// 修改带条件
public int update(final String statement, final Object param) {
return (Integer) execute(new SqlSessionCallback() {

public Object doInSqlSession(SqlSession session) {
if (param != null)
return session.update(statement, param);
else
return session.update(statement);
}
});
}

// 修改不带条件
public int update(final String statement) {
return update(statement, null);
}

// 增加带条件
public int insert(final String statement, final Object param) {
return (Integer) execute(new SqlSessionCallback() {

public Object doInSqlSession(SqlSession session) {
if (param != null)
return session.insert(statement, param);
else
return session.insert(statement);
}
});
}

// 增加不带条件
public int insert(final String statement) {
return insert(statement, null);
}

// 查询分页
public List selectList(final String statement, final Object param,
final RowBounds bounds) {
return executeFind(new SqlSessionCallback() {

public Object doInSqlSession(SqlSession session) {
if (statement == null)
throw new IllegalArgumentException(
"Sql 'statement' require");
if (bounds != null && param != null)
return session.selectList(statement, param, bounds);
else if (bounds!=null)
return session.selectList(statement, null, bounds);
else if (param != null) {
return session.selectList(statement, param);
}

else
return session.selectList(statement);

}
});
}

// 条件分页
public List selectList(final String statement, final Object param,
int skip, int limit) {
return selectList(statement, param, new RowBounds(skip, limit));
}

// 查询不分页
public List selectList(final String statement, final Object param) {
return selectList(statement, param, null);
}

// 查询不带条件
public List selectList(final String statement) {
return selectList(statement, null);
}

// 条件查带处理查询结果,带分页
public void select(final String statement, final Object param,
final RowBounds bounds, final ResultHandler handler) {
if (statement == null || handler == null)
throw new IllegalArgumentException(
"'statement' and 'handler' require");

execute(new SqlSessionCallback() {

public Object doInSqlSession(SqlSession session) {
if (handler != null && bounds != null && param != null)
session.select(statement, param, bounds, handler);
else if (bounds == null)
session.select(statement, param, handler);

return null;
}
});
}

// 自己处理查询结果 ,不带分页
public void select(final String statement, final Object param,
final ResultHandler handler) {
select(statement, param, null, handler);
}

// 查唯一结果
public Object selectOne(final String statement) {
return selectOne(statement, null);
}

// 查唯一结果带条件
public Object selectOne(final String statement, final Object param) {
if (statement == null)
throw new IllegalArgumentException("Sql 'statement' require");
return execute(new SqlSessionCallback() {

public Object doInSqlSession(SqlSession session) {
if (param != null)
return session.selectOne(statement, param);
else
return session.selectOne(statement);

}
});
}

}
package com.ibatis3;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import javax.sql.DataSource;

import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.taglibs.standard.tag.common.sql.DataSourceUtil;
import org.springframework.jdbc.datasource.DataSourceUtils;
import org.springframework.jdbc.support.JdbcAccessor;
import org.springframework.transaction.support.TransactionSynchronizationManager;

public class IBatis3DaoTemplate extends JdbcAccessor {
private SqlSessionFactory sessionFactory;

public IBatis3DaoTemplate(SqlSessionFactory factory) {
this.sessionFactory = factory;
}

public SqlSession openSession() {
SqlSession session = (SqlSession) TransactionSynchronizationManager
.getResource(sessionFactory);
if (session == null) {
session = sessionFactory.openSession();
}
return session;
}

public void setSessionFactory(SqlSessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}

public List executeFind(SqlSessionCallback callback) {
return (List) execute(callback);
}

public Object execute(SqlSessionCallback callback) {

SqlSession session = openSession();

Object obj = callback.doInSqlSession(session);
if (session != null)
session.close();

return obj;
}

// 删除,根据语句
public int delete(final String statement) {
return delete(statement, null);
}

// 删除,根据语句,带条件
public int delete(final String statement, final Object param) {
return (Integer) execute(new SqlSessionCallback() {

public Object doInSqlSession(SqlSession session) {
if (param != null)
return session.delete(statement, param);
else
return session.delete(statement);
}
});
}

// 修改带条件
public int update(final String statement, final Object param) {
return (Integer) execute(new SqlSessionCallback() {

public Object doInSqlSession(SqlSession session) {
if (param != null)
return session.update(statement, param);
else
return session.update(statement);
}
});
}

// 修改不带条件
public int update(final String statement) {
return update(statement, null);
}

// 增加带条件
public int insert(final String statement, final Object param) {
return (Integer) execute(new SqlSessionCallback() {

public Object doInSqlSession(SqlSession session) {
if (param != null)
return session.insert(statement, param);
else
return session.insert(statement);
}
});
}

// 增加不带条件
public int insert(final String statement) {
return insert(statement, null);
}

// 查询分页
public List selectList(final String statement, final Object param,
final RowBounds bounds) {
return executeFind(new SqlSessionCallback() {

public Object doInSqlSession(SqlSession session) {
if (statement == null)
throw new IllegalArgumentException(
"Sql 'statement' require");
if (bounds != null && param != null)
return session.selectList(statement, param, bounds);
else if (bounds!=null)
return session.selectList(statement, null, bounds);
else if (param != null) {
return session.selectList(statement, param);
}

else
return session.selectList(statement);

}
});
}

// 条件分页
public List selectList(final String statement, final Object param,
int skip, int limit) {
return selectList(statement, param, new RowBounds(skip, limit));
}

// 查询不分页
public List selectList(final String statement, final Object param) {
return selectList(statement, param, null);
}

// 查询不带条件
public List selectList(final String statement) {
return selectList(statement, null);
}

// 条件查带处理查询结果,带分页
public void select(final String statement, final Object param,
final RowBounds bounds, final ResultHandler handler) {
if (statement == null || handler == null)
throw new IllegalArgumentException(
"'statement' and 'handler' require");

execute(new SqlSessionCallback() {

public Object doInSqlSession(SqlSession session) {
if (handler != null && bounds != null && param != null)
session.select(statement, param, bounds, handler);
else if (bounds == null)
session.select(statement, param, handler);

return null;
}
});
}

// 自己处理查询结果 ,不带分页
public void select(final String statement, final Object param,
final ResultHandler handler) {
select(statement, param, null, handler);
}

// 查唯一结果
public Object selectOne(final String statement) {
return selectOne(statement, null);
}

// 查唯一结果带条件
public Object selectOne(final String statement, final Object param) {
if (statement == null)
throw new IllegalArgumentException("Sql 'statement' require");
return execute(new SqlSessionCallback() {

public Object doInSqlSession(SqlSession session) {
if (param != null)
return session.selectOne(statement, param);
else
return session.selectOne(statement);

}
});
}

}



四.Ibatis3DaoSupport支持类

Java代码
package com.ibatis3;

import org.springframework.dao.support.DaoSupport;

import org.springframework.transaction.support.TransactionSynchronizationManager;

import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSession;

import javax.sql.DataSource;
/*
* Dao类
* 主要接收传入的sessionFactory
* 取得模板
*/
public class Ibatis3DaoSupport extends DaoSupport {
private SqlSessionFactory sessionFactory;
private IBatis3DaoTemplate template;

public void createTemplate(){
this.template = new IBatis3DaoTemplate(sessionFactory);
}

public IBatis3DaoTemplate getTemplate() {
//System.out.println(template);
return template;
}

public void setTemplate(IBatis3DaoTemplate template) {
this.template = template;
}

//创建或得到session
public SqlSession openSession() {

SqlSession session = (SqlSession) TransactionSynchronizationManager
.getResource(sessionFactory);
if (session == null) {
session = sessionFactory.openSession();
}

return session;
}

public SqlSessionFactory getSessionFactory() {
return sessionFactory;
}

public void setSessionFactory(SqlSessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
this.template = new IBatis3DaoTemplate(sessionFactory);

}


@Override
protected void checkDaoConfig() throws IllegalArgumentException {

if (sessionFactory == null) {
throw new IllegalArgumentException(
"Property 'sessionFactory' or 'template' is required");
}

}

}
package com.ibatis3;

import org.springframework.dao.support.DaoSupport;

import org.springframework.transaction.support.TransactionSynchronizationManager;

import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSession;

import javax.sql.DataSource;
/*
* Dao类
* 主要接收传入的sessionFactory
* 取得模板
*/
public class Ibatis3DaoSupport extends DaoSupport {
private SqlSessionFactory sessionFactory;
private IBatis3DaoTemplate template;

public void createTemplate(){
this.template = new IBatis3DaoTemplate(sessionFactory);
}

public IBatis3DaoTemplate getTemplate() {
//System.out.println(template);
return template;
}

public void setTemplate(IBatis3DaoTemplate template) {
this.template = template;
}

//创建或得到session
public SqlSession openSession() {

SqlSession session = (SqlSession) TransactionSynchronizationManager
.getResource(sessionFactory);
if (session == null) {
session = sessionFactory.openSession();
}

return session;
}

public SqlSessionFactory getSessionFactory() {
return sessionFactory;
}

public void setSessionFactory(SqlSessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
this.template = new IBatis3DaoTemplate(sessionFactory);

}


@Override
protected void checkDaoConfig() throws IllegalArgumentException {

if (sessionFactory == null) {
throw new IllegalArgumentException(
"Property 'sessionFactory' or 'template' is required");
}

}

}


五.ibatis配置文件,我放在src下面

Java代码
<?xml version="1.0" encoding="UTF-8"?>
;!DOCTYPE configuration PUBLIC "-//ibatis.apache.org//DTD Config 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-config.dtd">

;configuration>
<mappers>
<mapper resource="com/pojos/Dep.xml"/>
</mappers>
;/configuration>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//ibatis.apache.org//DTD Config 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-config.dtd">

<configuration>
<mappers>
<mapper resource="com/pojos/Dep.xml"/>
</mappers>
</configuration>


很简单,就是装载些映射文件,其实可以sessionFactory中完成。

六. pojo类和映射文件就不贴出了,请看附件

七. spring的配置文件,用了声明式事务.

Java代码
<?xml version="1.0" encoding="UTF-8"?>

lt;beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!-- - - - - - - - Apache Dbcp Pool - - - - - - - -->
<bean id="datasource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver" />
<property name="username" value="scott" />
<property name="password" value="tiger" />
<property name="url"
value="jdbc:oracle:thin:@127.0.0.1:1521:ora92" />
</bean>

<!-- sqlMapClientSessionBean -->
<bean id="sessionFactory"
class="com.ibatis3.Ibatis3SessionFactory">
<property name="configLocation" value="sqlMapConfig.xml"></property>
<property name="dataSource" ref="datasource"></property>
</bean>

<!-- dao -->
<bean id="depDao" class="com.dao.DepDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<!-- - - - - - - spring Transaction Manager - - - - - - - -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="datasource" />
</bean>
<!-- - - - - - - spring Transaction Attribute - - - - - - - -->
<tx:advice id="transactionAdvice"
transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<!--****** weave *********-->
<aop:config>
<aop:advisor advice-ref="transactionAdvice"
pointcut="execution(* com.test.*.*(..))" />
</aop:config>


lt;/beans>


<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!-- - - - - - - - Apache Dbcp Pool - - - - - - - -->
<bean id="datasource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver" />
<property name="username" value="scott" />
<property name="password" value="tiger" />
<property name="url"
value="jdbc:oracle:thin:@127.0.0.1:1521:ora92" />
</bean>

<!-- sqlMapClientSessionBean -->
<bean id="sessionFactory"
class="com.ibatis3.Ibatis3SessionFactory">
<property name="configLocation" value="sqlMapConfig.xml"></property>
<property name="dataSource" ref="datasource"></property>
</bean>

<!-- dao -->
<bean id="depDao" class="com.dao.DepDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<!-- - - - - - - spring Transaction Manager - - - - - - - -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="datasource" />
</bean>
<!-- - - - - - - spring Transaction Attribute - - - - - - - -->
<tx:advice id="transactionAdvice"
transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<!--****** weave *********-->
<aop:config>
<aop:advisor advice-ref="transactionAdvice"
pointcut="execution(* com.test.*.*(..))" />
</aop:config>


</beans>

完整代码请下载下面附件,因本人水平有限,请勿用在生产环境:)

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/qqzhuyuehe/archive/2010/03/26/5419989.aspx

分享到:
评论

相关推荐

    iBatis和Spring整合

    iBatis和Spring整合 iBatis和Spring整合

    struts2 + spring2.5 + ibatis2.3.4整合包文件

    5. 整合过程:通常,整合这三大框架需要配置Struts2的struts.xml、Spring的applicationContext.xml以及iBatis的sqlMapConfig.xml等文件。还需要在Struts2的Action类中注入Spring管理的bean,以便于调用业务服务。...

    struts2+spring3+ibatis项目整合案例

    在这个“struts2+spring3+ibatis项目整合案例”中,我们将深入探讨这三个框架如何相互配合,实现项目的集成。 Struts2作为MVC(Model-View-Controller)架构的实现,主要负责处理用户请求,控制应用的流程。它提供...

    Spring对IBatis的整合

    #### 一、Spring与IBatis整合概述 Spring框架与IBatis(现称为MyBatis)的整合为开发者提供了一种更简洁、更强大的数据库访问方式。Spring通过其内置的支持机制极大地简化了原有的IBatis访问代码,并且提供了与...

    ibatis 与spring3整合

    "Ibatis 与 Spring3 整合"这一主题,涉及到的是两个知名Java框架——Ibatis(一个轻量级的持久层框架)和Spring(一个全面的企业级应用框架)的协同工作。下面我们将深入探讨这一整合过程中的关键知识点。 Ibatis ...

    ibatis与spring整合

    ### ibatis与Spring框架整合详解 #### 一、ibatis简介 ibatis是一个开源的、基于Java的持久层框架,它提供了SQL映射的方式来进行数据库访问。与Hibernate等其他ORM框架相比,ibatis更加轻量级,对于那些只需要简单...

    spring3.2与Ibatis整合

    7. **测试**:在Spring与iBatis整合后,可以使用Spring的`@Transactional`注解进行单元测试,确保每个方法都在独立的事务中执行,便于模拟各种数据状态并进行断言。 以上就是关于"Spring 3.2与iBatis整合"及"在...

    spring ibatis整合所需jar包

    1. 添加依赖:在`spring ibatis整合所需jar包`中,通常包含以下关键jar文件: - spring核心库:如spring-context、spring-beans、spring-aop等,用于Spring框架的基本功能。 - spring-jdbc和spring-tx:支持Spring...

    spring与ibatis整合集成实例

    3. **配置文件**:在整合过程中,需要配置两部分:Spring 配置文件(如 `applicationContext.xml`)和 iBATIS 配置文件(如 `sqlMapConfig.xml`)。Spring 配置文件中定义数据源、事务管理器以及 ...

    spring3 ibatis整合实例

    Spring3 和 iBatis 整合是一个常见的Java企业级应用开发模式,主要用于构建灵活、可扩展的后端数据访问层。这个项目实例提供了一个详细的学习资源,帮助新手掌握这两种技术的融合。以下是对这个整合实例的详细解析:...

    Spring+iBatis整合详解

    ### Spring与iBatis整合详解 #### 一、前言 在Java企业级应用开发中,Spring框架以其强大的依赖注入(DI)和面向切面编程(AOP)能力深受开发者喜爱,而iBatis(现更名为MyBatis)作为一款优秀的持久层框架,通过...

    ibatis spring struts 整合案例

    在这个特定的案例中,我们关注的是"Ibatis Spring Struts"的整合。这三个框架分别是:Ibatis(一个轻量级的持久层框架),Spring(一个全面的企业级应用开发框架),以及Struts(一个用于构建MVC(Model-View-...

    ibatis与spring的整合

    在整合iBATIS和Spring的过程中,主要目标是利用Spring的IOC(Inversion of Control)容器来管理和协调数据访问层(DAO)以及事务处理,同时利用iBATIS作为SQL映射框架,提供灵活的数据库操作。以下将详细阐述整合的...

    Ibatis Struts1.2 Spring 2.0 整合终极版

    Ibatis Struts1.2 Spring 2.0 整合终极版,Ibatis Struts1.2 Spring 2.0 整合终极版,Ibatis Struts1.2 Spring 2.0 整合终极版

    Struts2+iBATIS+Spring整合

    Struts2+iBATIS+Spring整合是Java Web开发中一种常见的技术栈组合,这三种框架协同工作,可以构建出高效、灵活的企业级应用。Struts2作为MVC(Model-View-Controller)架构的一部分,主要负责处理HTTP请求,管理前端...

    spring和ibatis整合

    整合Spring和iBatis,可以充分利用两者的优势,实现灵活、高效的数据库访问。以下是整合过程中的关键知识点: 1. **Spring的IoC容器**:Spring的核心是IoC容器,它负责创建对象、管理对象之间的关系以及执行对象的...

    spring_ibatis整合案例

    3. **配置Spring-iBatis** - **Spring配置**:创建Spring的配置文件(如`applicationContext.xml`),配置DataSource、SqlSessionFactoryBean以及SqlSessionTemplate或SqlSessionDaoSupport。DataSource用于连接...

    spring+struts2+ibatis整合的jar包

    当我们把Spring、Struts2和iBatis整合在一起时,可以构建出一个高效、模块化的Web应用。Spring作为整体的框架容器,负责管理所有的Bean,包括Struts2和iBatis的相关组件。Struts2处理HTTP请求,调用Spring管理的业务...

    struts1.3+spring2.5+ibatis2.3.4整合

    struts1.3+spring2.5+ibatis2.3.4整合

    Spring iBatis WebWork 整合

    Spring iBatis WebWork 整合

Global site tag (gtag.js) - Google Analytics