在使用注解的时候,需要注意的是,只能写在@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. NOIP 2018 记

    “这个时刻总是会来临的,日夜磨砺的剑锋,能否在今天展现出你的利刃呢?” 十一月十一日的紫荆港,早上的空气有些冷瑟.面对未知的$Day1$,我的心里尚且没有多少底数. $T1$是一道原题,也不难,并没有 ...

  2. bzoj4458 GTY的OJ (优先队列+倍增)

    把超级钢琴放到了树上. 这次不用主席树了..本来以为会好写一点没想到细节更多(其实是树上细节多) 为了方便,对每个点把他的那个L,R区间转化成两个深度a,b,表示从[a,b)选一个最小的前缀和(到根的 ...

  3. CSUOJ 1170 A sample problem

    J: A Simple Problem Submit Page   Time Limit: 1 Sec     Memory Limit: 128 Mb     Submitted: 87     S ...

  4. 蓝桥杯 算法提高 8皇后·改 -- DFS 回溯

      算法提高 8皇后·改   时间限制:1.0s   内存限制:256.0MB      问题描述 规则同8皇后问题,但是棋盘上每格都有一个数字,要求八皇后所在格子数字之和最大. 输入格式 一个8*8 ...

  5. Kubernetes之解决从k8s.gcr.io拉取镜像失败问题

    前言 因谷歌网络限制问题,国内的K8ser大多数在学习Kubernetes过程中因为镜像下载失败问题间接地产生些许失落感,笔者也因此脑壳疼,故翻阅资料得到以下解决方式: 在应用yaml文件创建资源时, ...

  6. Spring RedisTemplate操作-ZSet操作(6)

    @Autowired @Resource(name="redisTemplate") private RedisTemplate<String, String> rt; ...

  7. AngularJS 启程三

    <!DOCTYPE html> <html lang="zh_CN"> <head> <title>字数小例子</title& ...

  8. AngularJs -- 内置指令

    AngularJS提供了一系列内置指令.其中一些指令重载了原生的HTML元素,比如<form>和<a>标签, 当在HTML中使用标签时,并不一定能明确看出是否在使用指令. 其他 ...

  9. argunlar 1.0.0 【hello,world】

    <!DOCTYPE html><html lang="en" ng-app><head>    <meta charset="U ...

  10. Codeforces 238 div2 A. Gravity Flip

    题目链接:http://codeforces.com/contest/405/problem/A 解题报告:有n列箱子竖直放置,每列箱子上都有数量不等的箱子,这些箱子之间没有固定,当重力方向改为平行向 ...