SpringORM (ibatis)的一个例子

12 篇文章 0 订阅
11 篇文章 0 订阅
@Service
@Transactional
public class CommandManagerImpl extends IBatisDaoSupport implements
		CommandManager {

	@SuppressWarnings("unchecked")
	public List commandSetList() {
		List list = this.getSqlMapClientTemplate().queryForList(
				"CommandSet_listItem");
		return list;
	}

	@SuppressWarnings("unchecked")
	public String deleteCommandset(Map map) {
		this.getSqlMapClientTemplate().delete("CommandSet_deleteById", map);
		String num = (String) map.get("result");
		return num;

	}
 
import org.springframework.beans.factory.annotation.Autowired;
import com.ibatis.sqlmap.client.SqlMapClient;
public class IBatisDaoSupport extends
		org.springframework.orm.ibatis.support.SqlMapClientDaoSupport {

	/* 在配置文件中已经配置好的类的实例,spring容器在启动的时候会装载这个类,档程序运行到这里时,发现这个类需要自动注入一个SqlMapClient对象,就会从容器中把准备好的类的实例拿过来,以供类的使用
	 * 参考配置文件applicationContext-persistence.xml */
	@Autowired
	public void setSqlMapClientForAutowire(SqlMapClient sqlMapClient) {
		super.setSqlMapClient(sqlMapClient);
	}
}
 
<?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:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
		xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee"
		xmlns:tx="http://www.springframework.org/schema/tx"
		xsi:schemaLocation="
			http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
			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/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
			http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
	<context:annotation-config/>
	<tx:annotation-driven transaction-manager="transactionManager"/>
	<context:component-scan base-package="com.hzmc.capaa.business" />
</beans>
 
<?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:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:jee="http://www.springframework.org/schema/jee"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="
			http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
			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/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
			http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

	<import resource="applicationContext-propertyConfigurer.xml" />

	<!-- c3p0 datasource  -->
	<bean id="dataSource"
		class="com.mchange.v2.c3p0.ComboPooledDataSource"
		destroy-method="close" p:driverClass="${jdbc.driverClass}"
		p:jdbcUrl="${jdbc.jdbcUrl}" p:user="${jdbc.user}"
		p:password="${jdbc.password}">
		<property name="initialPoolSize"
			value="${jdbc.initialPoolSize}" />
		<property name="maxPoolSize" value="${jdbc.maxPoolSize}" />
	</bean>

	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
		p:dataSource-ref="dataSource" />
	<bean id="lobHandler"
		class="org.springframework.jdbc.support.lob.DefaultLobHandler" />
	
	<!-- ibatis support -->
	<bean id="sqlMapClient"
		class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
		<property name="configLocation"
			value="WEB-INF/config/ibatis/sqlmap-config.xml">
		</property>
		<property name="dataSource" ref="dataSource"></property>
		<property name="lobHandler" ref="lobHandler"/>  
	</bean>
</beans>
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值