springboot怎么使用事物注解
发表于:2024-09-29 作者:千家信息网编辑
千家信息网最后更新 2024年09月29日,这篇文章主要为大家展示了"springboot怎么使用事物注解",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"springboot怎么使用事物注解"这篇文章
千家信息网最后更新 2024年09月29日springboot怎么使用事物注解
这篇文章主要为大家展示了"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;@Servicepublic class UserService { @Autowired private UserMapper userMapper; public ListqueryAll(){ System.out.println("热部署"); return userMapper.findAll(); } @Transactional public void deleteById(Integer id) { userMapper.deleteById(id); // int c=10/0; }}
以上是"springboot怎么使用事物注解"这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!
注解
事物
内容
篇文章
接口
学习
帮助
业务
书屋
易懂
更多
条理
模式
版本
知识
编带
行业
资讯
资讯频道
频道
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
从云服务器
图书馆不同类型数据库
梦幻西游用什么软件开发的
网页服务器软件有哪些
服务器安全性能
久森互联网科技属于哪个区
软件开发风险管控措施
删除数据库的表命令
川藏线服务器
php 数据库 xml
软件开发设
邢台哪里有软件开发商家
js 软件开发应用
上海对高端网络安全人才政策
一梦江湖梯度服务器
服务器如何修改bmc时间
公安局网络安全宣传周材料
南沙区质量网络技术开发展示
贵阳司袒网络技术有限公司
杭州项目软件开发如何收费
双机热备软件开发
问道手游修改服务器ip
浙江网络技术开发包括什么
川藏线服务器
哪些图书馆能用wind数据库
软件开发技术服务包括
游戏服务器最大可以承载多少手机
手机可以配置阿里云服务器吗
防治网络安全
pe系统怎么修复服务器系统