springboot热部署+事务管理

热部署:

添加依赖:

<!--SpringBoot热部署配置 -->
<dependency>
  ``<groupId>org.springframework.boot</groupId>
  ``<artifactId>spring-boot-devtools</artifactId>
  ``<scope>runtime</scope>
  ``<optional>``true``</optional>
</dependency>

插件配置:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <excludes>
            <exclude>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
            </exclude>
        </excludes>
        <fork>true</fork>
        <addResources>true</addResources>
    </configuration>
</plugin>

项目配置(新版本默认配置,可不配)

#配置项目热部署
spring.devtools.restart.enabled=true

事务管理:

在service层对应的方法前用@Transactional标签

实例:

@Service
public class ClientService implements IClientService{
    @Autowired
    private ClientMapper clientMapper;

//事务管理
    @Override
    @Transactional
    public int zhuanzhang(String cname1, String cname2, double money) {
        Client client1 = clientMapper.queryClient(cname1);
        Client client2 = clientMapper.queryClient(cname2);

        if(money>client1.getMoney()){
            System.out.println("余额不足!");
            return 0;
        }

        client1.setMoney(client1.getMoney()-money);
        client2.setMoney(client2.getMoney()+money);

        clientMapper.updateMoney(client1);

//        System.out.println(10/0);

        clientMapper.updateMoney(client2);
        return 1;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值