spring 如何管理 ibatis 请教,spring 如何管理 ibatis包括它的事务、配置等等。最好有实例代码,配置文件。分不够可以再开。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://download.csdn.net/source/1211904这里有个struts2 + Spring + ibatis的例子可以借鉴一下 http://www.blogjava.net/landor2004/archive/2009/07/01/284978.html这是我的记录 context配置文件:<beans xmlns="http://www.springframework.org/schema/beans" 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"> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/ssh2" /> <property name="username" value="root" /> <property name="password" value="123" /> <property name="initialSize" value="1" /> <property name="maxActive" value="4" /> </bean> <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"> <property name="configLocation" value="classpath:sql-map-config.xml" /> <property name="dataSource" ref="dataSource" /> </bean> <!--事物代理配置---> <bean id="baseTxService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true"> <property name="transactionManager" ref="transactionManager" /> <property name="proxyTargetClass" value="true" /> <property name="transactionAttributes"> <props> <prop key="insert*">PROPAGATION_REQUIRED</prop> <prop key="query*">readOnly</prop> <prop key="get*">readOnly</prop> <prop key="del*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <bean id="testDao" class="login.dao.TestDAOImp"> <property name="sqlMapClient" ref="sqlMapClient"></property> </bean> <bean id="testService" class="login.service.TestService"> <property name="testDao" ref="testDao"></property> </bean> <bean id="testAction" class="login.web.TestAction" scope="prototype"> <property name="testService" ref="testService" /> </bean>sqlmap.xml<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-config-2.dtd"><sqlMapConfig> <settings cacheModelsEnabled="false" enhancementEnabled="false" maxSessions="64" maxTransactions="8" maxRequests="128"/> <sqlMap resource="login/mapping/User.xml"/> </sqlMapConfig>daopublic interface TestDAO { // public void insertUser(UserDomain ud) throws Exception; }daoimppublic class TestDAOImp extends SqlMapClientDaoSupport implements TestDAO { @Override public void insertUser(UserDomain ud) throws Exception { // TODO Auto-generated method stub// insert("insertUser",ud); getSqlMapClientTemplate().insert("insertUser", ud); }} 这个和Spring 整合 其他框架时 事务配置类似吧。我看 4 楼博客里面的例子基本的都说了啊。不行?? http://download.csdn.net/source/1211904 这里有个struts2 + Spring + ibatis的例子 可以借鉴一下 如果想要Insert UserListtry {[transaction start]for ( User user : UserList ) { getSqlMapClientTemplate().insert( "insertUser", user ); }[transaction commit]} cacth ( Exception e ) {[transaction rollback]}应该怎么办? 在spring 中有通知事务、前置事务,后置事务,还有aop ioc 都需要先了解一下。google MyEclipse8.5中使用Struts2的问题 初学问题 struts2.0 页面跳转回到原页面 图片无法显示 struts2中从/index.jsp跳转到/WEB-INF/jsp/login.jsp 如何将2007-07-25 00:00:00.000 自动转变成星期三 [求助]JSP登陆的问题 潜水好久了,分享一下SAP中国研究院的职位,有兴趣的xdjm进来看看吧! 关于用jsp/javamail实现pop3收信的问题 得到查询的记录数 ORACLE的问题,相信有很多人都遇到这个问题,也许也有很多人以解决,那就帮帮我哦! 问个问题哦 displayTag 分页标签问题
这里有个struts2 + Spring + ibatis的例子
可以借鉴一下
<beans
xmlns="http://www.springframework.org/schema/beans"
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">
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean> <bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName"
value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/ssh2" />
<property name="username" value="root" />
<property name="password" value="123" />
<property name="initialSize" value="1" />
<property name="maxActive" value="4" />
</bean>
<bean id="sqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation"
value="classpath:sql-map-config.xml" />
<property name="dataSource" ref="dataSource" />
</bean>
<!--事物代理配置--->
<bean id="baseTxService"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true">
<property name="transactionManager" ref="transactionManager" />
<property name="proxyTargetClass" value="true" />
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="query*">readOnly</prop>
<prop key="get*">readOnly</prop>
<prop key="del*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="testDao" class="login.dao.TestDAOImp">
<property name="sqlMapClient" ref="sqlMapClient"></property>
</bean>
<bean id="testService" class="login.service.TestService">
<property name="testDao" ref="testDao"></property>
</bean>
<bean id="testAction" class="login.web.TestAction"
scope="prototype">
<property name="testService" ref="testService" />
</bean>sqlmap.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-config-2.dtd"><sqlMapConfig> <settings
cacheModelsEnabled="false"
enhancementEnabled="false"
maxSessions="64"
maxTransactions="8"
maxRequests="128"/> <sqlMap resource="login/mapping/User.xml"/>
</sqlMapConfig>dao
public interface TestDAO {
//
public void insertUser(UserDomain ud) throws Exception;
}
daoimppublic class TestDAOImp extends SqlMapClientDaoSupport implements TestDAO { @Override
public void insertUser(UserDomain ud) throws Exception {
// TODO Auto-generated method stub
// insert("insertUser",ud);
getSqlMapClientTemplate().insert("insertUser", ud); }
}
这里有个struts2 + Spring + ibatis的例子
可以借鉴一下
for ( User user : UserList ) {
getSqlMapClientTemplate().insert( "insertUser", user );
}
[transaction commit]} cacth ( Exception e ) {[transaction rollback]}应该怎么办?
通知事务、前置事务,后置事务,还有aop ioc 都需要先了解一下。google