1.注入文章来源地址https://www.toymoban.com/news/detail-579136.html
@Resource private DataSourceTransactionManager dataSourceTransactionManager; @Resource private TransactionDefinition transactionDefinition;
@PostMapping("/findB00List")
@CrossOrigin
public Result findB00List(String ... b00) throws SQLException, IOException {
for (int i = 0; i < b00.length; i++) {
System.out.println(b00[i]);
}
//开启手动事务
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
//获取现在的时间
LambdaQueryWrapper<Dict> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Dict::getName,"dda");
List<Dict> list = dictService.list(wrapper);
Dict dict = new Dict();
String s1= "dadadada\n"+
"dadafawfawfaw\n";
dict.setVarchar1(s1);
dict.setVarchar2(s1);
dict.setVarchar3(s1);
dict.setName("侧睡事务");
dictService.save(dict);
//提交或者回滚事务
// dataSourceTransactionManager.rollback(transactionStatus);
dataSourceTransactionManager.commit(transactionStatus);
文章来源:https://www.toymoban.com/news/detail-579136.html
到了这里,关于springboot设置手动事务实战的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!