springBoot事物
在使用注解的时候,需要注意的是,只能写在@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事物的更多相关文章
- SpringBoot事物Transaction实战讲解教程
前言 本篇文章主要介绍的是SpringBoot的事物Transaction使用的教程. SpringBoot Transaction 说明:如果想直接获取工程那么可以直接跳到底部,通过链接下载工程代码 ...
- SpringBoot事物管理器
一.springboot整合事物管理 springboot默认集成事物,只主要在方法上加上@Transactional即可 二.SpringBoot分布式事物管理 使用springboot+jta+a ...
- springboot事物回滚
要添加事物 必须在方法上添加 @Transactional 注解 如果需要事物回滚有两个条件 1.方法中有异常或者主动抛异常 2.主动去回滚 TransactionAspectSupport.curr ...
- springboot数据库操作及事物管理操作例子
一.配置文件 pom.xml <dependency> <groupId>org.springframework.boot</groupId> <artifa ...
- springboot添加事务
(转自:http://www.cnblogs.com/xingzc/p/6029483.html) 什么是事务? 我们在开发企业应用时,对于业务人员的一个操作实际是对数据读写的多步操作的结合.由于数据 ...
- SpringBoot 中的使用事务
转自:https://blog.csdn.net/linzhiqiang0316/article/details/52638039 什么是事务? 我们在开发企业应用时,对于业务人员的一个操作实际是对数 ...
- SpringBoot切面Aop的demo简单讲解
前言 本篇文章主要介绍的是SpringBoot切面Aop的demo简单讲解. SpringBoot Aop 说明:如果想直接获取工程那么可以直接跳到底部,通过链接下载工程代码. 切面(Aop) 一.概 ...
- SpringBoot整合Guacamole教程
前言 本文主要介绍的是SpringBoot如何整合Guacamole在浏览器是远程桌面的访问. Guacamole 介绍 Apache Guacamole 是一个无客户端远程桌面网关.它支持标准协议, ...
- SpringCloud 别人的主页
https://www.cnblogs.com/xuwujing/ java(28) springBoot(14) 设计模式(14) springcloud(7) hadoop(7) hive(5) ...
随机推荐
- sqlplus执行startup出现ORA-00119,ORA-00132错误
安装好了oracle后,执行如下操作: 执行startup后出现如下错误: ORA-00119: invalid specification for system parameter LOCAL_LI ...
- AtCoder Grand Contest 010
AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...
- laravel 单元测试设置模拟时间
有时候我们需要对一些超时的逻辑进行测试,需要等待一定的时间来验证超时逻辑是否生效. Carbon 库提供了 setTestNow 方法来设置一个虚拟的当前时间 使用这个特性的前提是:我们的待测试代码利 ...
- harbor高可用集群配置
目录 说明 双主复制 主从同步 双主复制说明 多harbor实例共享后端存储 方案说明 环境说明 配置说明 安装redis和mysql 导入registry数据库 配置harbor 挂载nfs目录 修 ...
- 卸载并安装指定版本Angular CLI
1.卸载之前的版本 npm uninstall -g @angular/cli 2.清除缓存,确保卸载干净 npm cache clean 3.检查是否卸载干净 输入命令 ng -v 若显示comma ...
- bzoj千题计划260:bzoj2940: [Poi2000]条纹
http://www.lydsy.com/JudgeOnline/problem.php?id=2940 SG 博弈入门推荐张一飞的<由感性认识到理性认识 ——透析一类搏弈游戏的解答过程> ...
- Codeforces 314 E. Sereja and Squares
http://codeforces.com/contest/314/problem/E 题意: 原本有一个合法的括号序列 擦去了所有的右括号和部分左括号 问有多少种填括号的方式使他仍然是合法的括号序列 ...
- ngx_lua_API 指令详解(二)ngx.re.match/find/gmatch/sub/gsub指令集合
1.先来个官方的ngx.re.match location /ngx_re_match { default_type text/html; content_by_lua_block { local m ...
- 进程ID[PID(Process ID)]与端口号[(Port ID)]的联系
1.首先声明一点:PID不是端口(port id),而是Process ID进程号的意思. 2.那么,什么是进程号? 采集网友的意见就是: 进程号,是系统分配给么一个进程的唯一标识符.PID就是各进程 ...
- 由一篇吐槽对String空字符串判断的文章所引发的碎碎念
一.起因 最近有篇关于String空字符串判断的文章火了,老是看到这篇文章,既然如此我也只好认真看了下:程序员晒出一段代码引来无数网友狂喷!网友:你就活该当码农! 我也觉得这段代码写的不怎么的,首先程 ...