以前学ssh ssm都有事务管理service层通过applicationContext.xml配置,所有service方法都加上事务操作;

用来保证一致性,即service方法里的多个dao操作,要么同时成功,要么同时失败;

springboot下的话 一个@Transactional即可搞定;

我们这里搞一个实例,转账实例,A用户转账给B用户xx元

设计如下:

Account类

 1 package com.hik.entity;
 2 
 3 import javax.persistence.Column;
 4 import javax.persistence.Entity;
 5 import javax.persistence.GeneratedValue;
 6 import javax.persistence.Id;
 7 import javax.persistence.Table;
 8 
 9 /**
10  * 账户实体
11  * @author jed
12  *
13  */
14 @Entity
15 @Table(name="t_account")
16 public class Account {
17 
18     @Id
19     @GeneratedValue
20     private Integer id;
21     
22     @Column(length=50)
23     private String userName;
24     
25     private float balance;
26 
27     public Integer getId() {
28         return id;
29     }
30 
31     public void setId(Integer id) {
32         this.id = id;
33     }
34 
35     public String getUserName() {
36         return userName;
37     }
38 
39     public void setUserName(String userName) {
40         this.userName = userName;
41     }
42 
43     public float getBalance() {
44         return balance;
45     }
46 
47     public void setBalance(float balance) {
48         this.balance = balance;
49     }
50     
51     
52 }
View Code

相关文章:

  • 2021-05-31
  • 2021-10-01
  • 2022-12-23
  • 2021-07-14
  • 2021-12-05
  • 2021-12-31
  • 2022-12-23
猜你喜欢
  • 2021-06-08
  • 2021-07-27
  • 2021-08-30
  • 2021-09-29
  • 2022-12-23
  • 2021-08-07
相关资源
相似解决方案