留号码的广告网站不需要验证码,企业网络的构建与实施,根据网站集约化建设要求,方案策划网站1.概念 事务就是用户定义的一系列执行SQL语句的操作, 这些操作要么完全地执行#xff0c;要么完全地都不执行#xff0c; 它是一个不可分割的工作执行单元 一个使用Mybatis-Spring的主要原因是它允许Mybatis参与到Spring的事务管理中#xff0c;而不是给Mybatis创建一个新的…1.概念 事务就是用户定义的一系列执行SQL语句的操作, 这些操作要么完全地执行要么完全地都不执行 它是一个不可分割的工作执行单元 一个使用Mybatis-Spring的主要原因是它允许Mybatis参与到Spring的事务管理中而不是给Mybatis创建一个新的专用事务管理器 2.步骤
2.1.spring配置文件
?xml version1.0 encodingUTF-8?
beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:txhttp://www.springframework.org/schema/tx xmlns:aophttp://www.springframework.org/schema/aopxsi:schemaLocationhttp://www.springframework.org/schema/beanshttps://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd!--Spring整合Mybatis省略了Mybatis的核心配置文件转而在Spring的配置文件中配置Mybatis--!--datasource--bean iddataSource classorg.springframework.jdbc.datasource.DriverManagerDataSourceproperty namedriverClassName valuecom.mysql.cj.jdbc.Driver/property nameurl valuejdbc:mysql://localhost:3306/user?useSSLfalseamp;useUnicodetrueamp;characterEncodingUTF-8/property nameusername valueroot/property namepassword value123456//bean!--sqlSessionFactory--bean idsqlSessionFactory classorg.mybatis.spring.SqlSessionFactoryBeanproperty namedataSource refdataSource /
!-- property nameconfigLocation valueclasspath:mybatis-config.xml/--property namemapperLocations valueclasspath:com/sun/mapper/*.xml//bean!--SqlSessionTemplate:就是我们使用的sqlSession,这个是spring提供的--bean idsqlSessionTemplate classorg.mybatis.spring.SqlSessionTemplate!--我们只能使用构造器注入因为没有set方法--constructor-arg namesqlSessionFactory refsqlSessionFactory//beanbean idUserMapperImpl classcom.sun.mapper.UserMapperImplproperty namesqlSessionTemplate refsqlSessionTemplate//bean
/beans 2.2.配置声明式事务
!--配置声明式事务--
bean idtransationManage classorg.springframework.jdbc.datasource.DataSourceTransactionManagerproperty namedataSource refdataSource/
/bean
2.3.用AOP的方式实现事务 !--结合AOP实现事务的织入--!--第一步配置事务的通知--tx:advice idtxAdvice transaction-managertransationManagetx:attributestx:method name* propagationREQUIRED//tx:attributes/tx:advice
2.4.配置事务切入 aop:configaop:pointcut idPointCut expressionexecution(* com.sun.mapper.*.*(..))/aop:advisor advice-reftxAdvice pointcut-refPointCut//aop:config