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://csdahua.cn/article/dgspcs.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流