springBoot事务管理
来源:互联网 发布:100以内质数的和c语言 编辑:程序博客网 时间:2024/06/04 18:01
springBoot事务管理
demo:
GirlController:
@RestControllerpublic class GirlController { @Autowired private GirlRepository girlRepository; @Autowired private GirlService girlService; /** * 插入(事物管理) */ @PostMapping(value = "/girls/two") public void girlTwo(){ girlService.insertTwo(); }}
GirlService:
@Servicepublic class GirlService { @Autowired private GirlRepository girlRepository; /** * 事务管理 * 该方法中的两个操作要么都成功,要么都失败 * 一般只有一个操作也要加事务管理,只要查询不需要加 */ @Transactional public void insertTwo(){ Girl girlA = new Girl(); girlA.setCupSize("A"); girlA.setAge(18); girlRepository.save(girlA); Girl girlB = new Girl(); girlA.setCupSize("B"); girlA.setAge(19); girlRepository.save(girlB); }}
GirlRepository:
public interface GirlRepository extends JpaRepository<Girl,Integer> { /**JpaRepository<> * 第一个参数:类名 * 第二个参数:id的类型 */ //通过年龄来查询 public List<Girl> findByAge(Integer age);}
Girl:
@Entity //该注解表示该类在数据库中有对应的表 不用创建该表public class Girl { @Id @GeneratedValue private Integer id; private String cupSize; private Integer age; public Girl() { }
applicaion.yml:
spring: profiles: active: prod datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/dbgirl username: root password: 123456 jpa: hibernate: ddl-auto: create show-sql: true
阅读全文
0 0
- springboot事务管理
- SpringBoot事务管理
- springboot事务管理
- SpringBoot 事务管理
- springBoot事务管理
- springboot事务管理
- SpringBoot事务管理
- SpringBoot事务管理
- springboot+mybatis 事务管理
- springboot中的事务管理
- Springboot 事务管理控制
- springboot【14】事务管理
- SpringBoot+Mybatis事务管理
- SpringBoot中的事务管理
- springboot【29】事务管理
- springboot事务管理详解
- springboot分布式事务管理(atomikos)
- Springboot入门之分布式事务管理
- iwebshop添加邀请用户功能-邮箱邀请
- list遍历出来的值都一样
- pthread(一)
- 浅谈数据结构_堆[更新中]
- Farey Sequence
- springBoot事务管理
- HDU 6130 Kolakoski
- 使用AD13设计PCB的技巧总结
- Intellij IDEA WEB项目部署配置
- Spring cloud实战-Zuul如何动态负载和服务发现扩容
- 对公客户查询账户详情——第一次写模型
- python编程 强制转换编码utf-8
- Redis 优势以及与其他key-value存储的不同
- Spring cloud实战-Fegin简易使用