在使用注解的时候,需要注意的是,只能写在@Service的类中才能生效。

1.事物

  只是需要一个注解即可

2.事物程序

 package com.caojun.springboot;

 import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; @Service
public class TransactionService { @Autowired
private StudentResitory studentResitory; @Transactional
public void insertTwo(){
Student student1=new Student();
student1.setName("AA");
student1.setAge(33);
studentResitory.save(student1); Student student2=new Student();
student2.setName("BB");
student2.setAge(44);
studentResitory.save(student2);
}
}

3.验证程序

 @RestController
public class StudentController { @Autowired
private StudentResitory studentResitory; @Autowired
private TransactionService transactionService; /**
* 数据库事物
*/
@GetMapping(value = "/hello/insertTwo")
public void insertStu(){
transactionService.insertTwo();
}

4.效果

  

springBoot事物的更多相关文章

  1. SpringBoot事物Transaction实战讲解教程

    前言 本篇文章主要介绍的是SpringBoot的事物Transaction使用的教程. SpringBoot Transaction 说明:如果想直接获取工程那么可以直接跳到底部,通过链接下载工程代码 ...

  2. SpringBoot事物管理器

    一.springboot整合事物管理 springboot默认集成事物,只主要在方法上加上@Transactional即可 二.SpringBoot分布式事物管理 使用springboot+jta+a ...

  3. springboot事物回滚

    要添加事物 必须在方法上添加 @Transactional 注解 如果需要事物回滚有两个条件 1.方法中有异常或者主动抛异常 2.主动去回滚 TransactionAspectSupport.curr ...

  4. springboot数据库操作及事物管理操作例子

    一.配置文件 pom.xml <dependency> <groupId>org.springframework.boot</groupId> <artifa ...

  5. springboot添加事务

    (转自:http://www.cnblogs.com/xingzc/p/6029483.html) 什么是事务? 我们在开发企业应用时,对于业务人员的一个操作实际是对数据读写的多步操作的结合.由于数据 ...

  6. SpringBoot 中的使用事务

    转自:https://blog.csdn.net/linzhiqiang0316/article/details/52638039 什么是事务? 我们在开发企业应用时,对于业务人员的一个操作实际是对数 ...

  7. SpringBoot切面Aop的demo简单讲解

    前言 本篇文章主要介绍的是SpringBoot切面Aop的demo简单讲解. SpringBoot Aop 说明:如果想直接获取工程那么可以直接跳到底部,通过链接下载工程代码. 切面(Aop) 一.概 ...

  8. SpringBoot整合Guacamole教程

    前言 本文主要介绍的是SpringBoot如何整合Guacamole在浏览器是远程桌面的访问. Guacamole 介绍 Apache Guacamole 是一个无客户端远程桌面网关.它支持标准协议, ...

  9. SpringCloud 别人的主页

    https://www.cnblogs.com/xuwujing/ java(28) springBoot(14) 设计模式(14) springcloud(7) hadoop(7) hive(5) ...

随机推荐

  1. python 用Threading创建多线程

    #-*-coding:utf-8-*- '''python标准库提供了两个多线程模块,分别为thread和threading, 其中thread模块是低级模块,threading是高级模块,对thre ...

  2. mysql concat_ws 与 concat 多字段模糊匹配应用

    有时我们希望在表中多个字段检索是否有我们给出的关键字,我们可以使用 concat_ws 和 concat 连接需要检索的字段,如: select * from userInfo where conca ...

  3. vue中assets文件夹与static文件夹的区别

    1.如果这些产品图片文件“万年不变”,放在 /static 目录里,(不需要使用require将这些图片作为模块来引用) var products = [{ img: '/static/img/pro ...

  4. [应用篇]第六篇 JSTL之自定义函数标签库

      在之前的JSTL的总结中已经对函数标签库进行了一些说明,在这里我再一次重新整理一下! 自带函数标签库介绍 引入该标签库的方法为: <%@ taglib prefix="fn&quo ...

  5. 贪心算法:Codevs 1044 拦截导弹

    ---恢复内容开始--- #include <iostream> #include <cstdio> #include <cstdlib> #include < ...

  6. 用matplotlib制作的比较满意的蜡烛图

    用matplotlib制作的比较满意的蜡烛图 2D图形制作包, 功能强大, 习练了很久, 终于搞定了一个比较满意的脚本. 特点: 使用方面要非常简单 绘制出来的图要非常的满意, 具有如下的特点 时间和 ...

  7. ASP.NET MVC学习(五)之MVC原理解析

    ASP.NET MVC 请求生命周期 生命周期步骤概览 当我们对ASP.NET MVC网站发出一个请求的时候,会发生5个主要步骤: 步骤1:创建RouteTable 当ASP.NET应用程序第一次启动 ...

  8. javascript沙箱模式

    沙箱模式解决了命名空间模式的如下几个缺点: 1.对单个全局变量的依赖变成了应用程序的全局变量依赖.在命名空间模式中,是没有办法使同一个应用程序或库的2个版本运行在同一个页面中.2.对这种以点分割的名字 ...

  9. TED_Topic7:How we unearthed the spinosaurus

    By Nizar Ibrahim A 50-foot-long carnivore who hunted its prey in rivers 97 million years ago, the sp ...

  10. 第9月第7天 uicollectionview

    1. /** The margins used to lay out content in the section controller. @see `-[UICollectionViewFlowLa ...