Springmybatis.xml
<Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns:p= "http://www.springframework.org/schema/p"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:mvc= "Http://www.springframework.org/schema/mvc"Xmlns:tx= "Http://www.springframework.org/schema/tx"xsi:schemalocation= "Http://www.springframework.org/schema/beans HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/BEANS/SPR Ing-beans-3.1.xsd Http://www.springframework.org/schema/context http://w Ww.springframework.org/schema/context/spring-context-3.1.xsd Http://www.springframework.org/schem A/MVC http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd/HTTP Www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-a Op.xsd "> <Context:component-scanBase-package= "COM.SCSMSJK"></Context:component-scan> <!--introducing a configuration file - <BeanID= "Propertyconfigurer"class= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> < Propertyname= "Location"value= "Classpath:jdbc.properties" /> </Bean> <BeanID= "DataSource"class= "Org.apache.commons.dbcp.BasicDataSource"Destroy-method= "Close"> < Propertyname= "Driverclassname"value= "${driver}" /> < Propertyname= "url"value= "${url}" /> < Propertyname= "username"value= "${username}" /> < Propertyname= "Password"value= "${password}" /> <!--Initialize connection size connect Oracle database without the following configuration - < Propertyname= "InitialSize"value= "${initialsize}" /> <!--maximum number of connection pools - < Propertyname= "Maxactive"value= "${maxactive}" /> <!--Maximum idle connection pool - < Propertyname= "Maxidle"value= "${maxidle}" /> <!--Connection Pool min idle - < Propertyname= "Minidle"value= "${minidle}" /> <!--Get connection Maximum wait time - < Propertyname= "Maxwait"value= "${maxwait}" /> </Bean> <!--sqlsessionfactory Configuration - <BeanID= "Sqlsessionfactory"class= "Org.mybatis.spring.SqlSessionFactoryBean"> < Propertyname= "DataSource"ref= "DataSource" /> < Propertyname= "Mapperlocations"value= "Classpath:com/scsmsjk/mapper/*.xml"></ Property> < Propertyname= "Configlocation"value= "Classpath:sqlMapConfig.xml" /> < Propertyname= "Typealiasespackage"value= "Com.nhinter.entity"/> <!--<property name= "Plugins" > <array> paging Plug-in configuration <bean id= "pagination Interceptor "class=" Com.xyb2c.plugin.PaginationInterceptor "/> </array> </property> - </Bean> <Beanclass= "Org.mybatis.spring.mapper.MapperScannerConfigurer"> < Propertyname= "Sqlsessionfactorybeanname"value= "Sqlsessionfactory"></ Property> < Propertyname= "Basepackage"value= "Com.scsmsjk.dao"></ Property> </Bean> <BeanID= "TransactionManager"class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager"> < Propertyname= "DataSource"ref= "DataSource" /> </Bean> <Tx:annotation-drivenTransaction-manager= "TransactionManager"/></Beans>
Service Layer
Package Com.scsmsjk.serviceimp;import Java.util.list;import Org.springframework.beans.factory.annotation.autowired;import Org.springframework.stereotype.service;import Org.springframework.transaction.annotation.isolation;import Org.springframework.transaction.annotation.propagation;import Org.springframework.transaction.annotation.transactional;import Com.scsmsjk.dao.tsmshassentmapper;import Com.scsmsjk.dao.tsmssendingmapper;import Com.scsmsjk.entity.tsmssending;import com.scsmsjk.service.SmsService;@ Service@transactional (rollbackfor=exception.class) public class Smsserviceimp implements SMSService {@ Autowiredtsmssendingmapper Tsmssenddao, @AutowiredTsmsHassentMapper tsmshassentdao;public list<tsmssending> SelectAll () {return Tsmssenddao.selectall ();} @Transactional (propagation=propagation.required, isolation=isolation.read_committed, readonly=false) public int Deletebyprimarykey (Integer fId) {int aa=tsmshassentdao.deletebyprimarykey (n); int Cc=aa/0;return Tsmssenddao.deletebyprimarykEY (fId);}}
Spring, mybatis transaction configuration and control