谢茂盛
authored
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
package com.canrd.webmagic.common.utils;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.function.Supplier;
/**
* @author:
* @date: 2021/12/21
*/
@Component
public class TransactionHelper {
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public <T> T run(Supplier<T> command) {
return command.get();
}
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public void run(Runnable command) {
command.run();
}
}
|