此链接: https: //www.quora.com/When-should-Spring-Boot-methods-use-the-Transactional-annotation
解释清楚@Transactional是做什么的,但我还是不明白Spring Boot方法什么时候应该使用这个注解:
例如:
我有这个方法:
void addPerson () {// code that calls the DAO layer}
Run Code Online (Sandbox Code Playgroud)
我的方法在没有@Transactional注释的情况下也能正常工作,那么为什么我应该添加这个注释。
更准确地说(在 Spring Boot 中)有什么区别:
@Transactional void addPerson () {// code that calls the DAO layer}
Run Code Online (Sandbox Code Playgroud)
和
void addPerson () {// code that calls the DAO layer}
Run Code Online (Sandbox Code Playgroud)
或者Spring boot会自动添加这个注释,这样我们就不需要将它添加到我们的服务中