标签:
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{ }
<bean id="userDao" class="com.foo.dao.UserDAOImpl"> <property name="sqlMapClient" ref="sqlMapClient"/> <!-- 装配SqlMapClientFactoryBean --> </bean>
标签:
原文地址:http://blog.csdn.net/u010081710/article/details/43673085