这篇文章中有说到 @Transactional
标注的方法也有锁的情况下会出现一些问题,具体请看 Spring Boot 锁。
而且 Idea 也会标一个黄色波浪线提示你。我是这样做的,仅供参考。
file:[DiscussionService.java]
@Service
public class DiscussionService implements IDiscussionService {
private final DiscussionMapper discussionMapper;
private final TransactionalWrapper transactionalWrapper;
public DiscussionService(DiscussionMapper discussionMapper) {
this.discussionMapper = discussionMapper;
transactionalWrapper = new TransactionalWrapper(discussionMapper);
}
@Override
public synchronized int upgradeArticle(ArticleModel model, DiscussionCriteria criteria) {
return transactionalWrapper.doUpgradeArticle(model, criteria);
}
}
@AllArgsConstructor
class TransactionalWrapper {
private DiscussionMapper discussionMapper;
@Transactional
public int doUpgradeArticle(ArticleModel model, DiscussionCriteria criteria) {
try {
// ...
Integer affectRows = discussionMapper.upgradeArticle(model);
return affectRows > 0 ? 1 : 0;
} catch (Exception e) {
throw new JdbcErrorException(e);
}
}
}
标签:synchronized,Spring,Transactional,criteria,discussionMapper,model,public
From: https://www.cnblogs.com/Himmelbleu/p/17802069.html