首页 > 编程语言 > 详细

spring2.5整合ibatis

时间:2015-02-09 23:14:45      阅读:503      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!