ssm框架中开启事务

在service层中 加入配置文件

applicationContext.xml

<?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:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
 

    <!-- 事务管理器  -->  
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
        <property name="dataSource" ref="dataSource" />  
    </bean>  
      
    <!-- 开启事务控制的注解支持 -->  
    <tx:annotation-driven transaction-manager="transactionManager"/>
   
</beans>

再去需要控制的类上加上注解

@Transactional

public class ServiceImpl implements Service {

}

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
SSM(Spring + SpringMVC + MyBatis)框架,有许多常用的注解,下面是它们的详细解释: 1. @Controller:用于标识控制层组件,相当于在 Spring 的 @Component。 2. @Service:用于标识服务层组件,相当于在 Spring 的 @Component。 3. @Repository:用于标识 DAO 层组件,相当于在 Spring 的 @Component。 4. @Autowired:自动装配,用于自动注入其他组件的实例。 5. @Resource:自动装配,用于自动注入其他组件的实例,与 @Autowired 类似,但它是按照名称进行注入。 6. @RequestMapping:映射处理器,用于处理请求和响应的映射关系。 7. @RequestParam:用于获取请求参数的值。 8. @PathVariable:用于获取请求路径的参数值。 9. @ResponseBody:用于将方法的返回值转换为 JSON 格式返回给客户端。 10. @Transactional:事务注解,用于开启事务管理。 11. @Aspect:切面注解,用于定义切面,实现面向切面编程。 12. @Before:前置通知注解,用于在目标方法执行前执行通知。 13. @AfterReturning:后置通知注解,用于在目标方法执行后执行通知。 14. @AfterThrowing:异常通知注解,用于在目标方法抛出异常时执行通知。 15. @Around:环绕通知注解,用于在目标方法执行前后执行通知。 16. @Pointcut:切点注解,用于定义切点,指定切面作用的方法。 以上是常用的 SSM 框架的注解,掌握它们对于快速开发高效的项目是非常有帮助的。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值