码迷,mamicode.com
首页 > 编程语言 > 详细

spring2.5整合ibatis

时间:2015-02-09 23:14:48      阅读:304      评论:0      收藏:0      [点我收藏+]

标签:

SqlMapClient对象 

这个对象是iBatis操作数据库的接口(执行CRUD等操作),它也可以执行事务管理等操作。这个类是我们使用iBATIS的最主要的类。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
        "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
    
<span style="white-space:pre">	</span><bean id="IqDataSource"
		class="org.springframework.jndi.JndiObjectFactoryBean">
		<property name="jndiName">
			<value>java:comp/env/jdbc/awpiq</value>
		</property>
<span style="white-space:pre">	</span></bean>    
	
	<bean id="sqlMap_iqClient"
		class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
		<property name="configLocation"> 
			<value>SqlMapIqConfig.xml</value> 
		</property>
		<property name="transactionConfigClass"
			ref="transactionConfigClass" />
		<property name="dataSource" ref="IqDataSource" />
	</bean>
	
	<bean id="transactionConfigClass" class="java.lang.Class"
		factory-method="forName">
		<constructor-arg index="0"
			value="com.ibatis.sqlmap.engine.transaction.jdbc.JdbcTransactionConfig" />
	</bean>
	
</beans>

DefaultSqlMap.java

package com.bank.common;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class DefaultSqlMap {
	public static ApplicationContext context = null;
	static{
		 context=new ClassPathXmlApplicationContext(
				new String[]{"applicationContext-Iq.xml"}
		);  
	}
}

SqlMapIqFactory.java

package com.bank.common;

import com.ibatis.sqlmap.client.SqlMapClient;

public class SqlMapIqFactory extends DefaultSqlMap
{	
	private static SqlMapClient sqlMap = null;
	
	static{
		
		sqlMap=(SqlMapClient) context.getBean("sqlMap_iqClient"); 
	}
	public static SqlMapClient getSqlMapInstance(){	
		return sqlMap; 
	} 
}
SqlMapIqConfig.xml

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

<!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
    "http://www.ibatis.com/dtd/sql-map-config-2.dtd">

<sqlMapConfig>
	<sqlMap resource="com/foo/maps/user.xml"/>
</sqlMapConfig>
UserDAOImpl.java

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport; 

public class UserDAOImpl extends SqlMapClientDaoSupport{ 

}

spring管理bean dao

<bean id="userDao" class="com.foo.dao.UserDAOImpl">    
	<property name="sqlMapClient" ref="sqlMapClient"/> 
	<!-- 装配SqlMapClientFactoryBean -->   
</bean>


spring2.5整合ibatis

标签:

原文地址:http://blog.csdn.net/u010081710/article/details/43673085

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!