[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
手动开启事务/保存点/隐式发出commit的语句
1.手动开启事务 @Autowired DataSourceTransactionManager dataSourceTransactionManager;
@Autowired TransactionDefinition transactionDefinition; TransactionStatus
transactionStatus =
dataSourceTransactionManager.getTransaction(transactionDefinition);//transactionDefinition可以设置事务类型等
等价于TransactionStatus transactionStatus
=TransactionAspectSupport.currentTransactionStatus();//获取@Transactional方式的当前事务
手动提交事务 dataSourceTransactionManager.commit(transactionStatus);//提交 手动回滚事务
dataSourceTransactionManager.rollback(transactionStatus);//最好是放在catch
里面,防止程序异常而事务一直卡在哪里未提交 2.保存点 官网语法 SAVEPOINT identifier ROLLBACK [WORK] TO
[SAVEPOINT] identifier RELEASE SAVEPOINT identifier 测试 mysql> BEGIN; mysql>
INSERT INTO T2 VALUES(100); mysql> SAVEPOINT svp1; mysql> INSERT INTO T2
VALUES(200); mysql> ROLLBACK TO SAVEPOINT svp1; mysql> RELEASE SAVEPOINT svp1;
mysql> COMMIT; mysql> SELECT * FROM T2; +------+ | ID | +------+ | 100 |
+------+ 1 row in set (0.00 sec) 1.注意的问题是保存点只能回滚不能提交保存点
2.注意Savepoint1中如果有Savepoint2嵌套 则回滚会把Savepoint2也回滚
3.这种方式又延迟需要等到方法完成才能起作用(如果嵌套有其他逻辑最终可能会导致失败) Object savepoint =
TransactionAspectSupport.currentTransactionStatus().createSavepoint();//创建Savepoint
TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savepoint);//回滚指定的Savepoint
TransactionAspectSupport.currentTransactionStatus().releaseSavepoint(savepoint);//释放指定的Savepoint
3.隐式发出commit的语句 1.DDL语句 2.隐式地使用或者修改mysql数据库的语句 ALTER USER, CREATE USER, DROP
USER, GRANT, RENAME USER, REVOKE, SET PASSWORD 3.事务控制和锁语句,比如BEGIN,START
TRANSACTION, LOCK/UNLOCK TABLES, SET autocommit = 1(原来不是1)