怎么在springboot中使用事物注解-创新互联
今天就跟大家聊聊有关怎么在springboot中使用事物注解,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

1.在启动类Application中添加注解@EnableTransactionManagement
import tk.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication
@EnableTransactionManagement //开启书屋管理注解模式 最新的版本可以省略
@MapperScan("com.xz.springboot.mapper") //扫描该包下所有的接口并为该接口生成实现类
public class Springboot01Application {
public static void main(String[] args) {
SpringApplication.run(Springboot01Application.class, args);
}
}2.在业务层添加@Transactional
import com.xz.springboot.bean.User;
import com.xz.springboot.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
public class UserService {
@Autowired
private UserMapper userMapper;
public List queryAll(){
System.out.println("热部署");
return userMapper.findAll();
}
@Transactional
public void deleteById(Integer id) {
userMapper.deleteById(id);
// int c=10/0;
}
} 看完上述内容,你们对怎么在springboot中使用事物注解有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联网站建设公司行业资讯频道,感谢大家的支持。
另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网页题目:怎么在springboot中使用事物注解-创新互联
文章来源:http://www.scyingshan.cn/article/dciodd.html


咨询
建站咨询
