资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

springboot怎么使用事物注解

这篇文章主要为大家展示了“springboot怎么使用事物注解”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“springboot怎么使用事物注解”这篇文章吧。

创新互联建站专业为企业提供集安网站建设、集安做网站、集安网站设计、集安网站制作等企业网站建设、网页设计与制作、集安企业网站模板建站服务,10多年集安做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

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 List queryAll(){      System.out.println("热部署");      return userMapper.findAll();    }  @Transactional  public void deleteById(Integer id) {      userMapper.deleteById(id);     // int c=10/0;  }}

以上是“springboot怎么使用事物注解”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!


文章标题:springboot怎么使用事物注解
当前地址:http://cdkjz.cn/article/gigsid.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220