编程式事务

    @Resource
    private TransactionTemplate transactionTemplate;
    @Override
    public Object getTest() {
        Student student = new Student();
        student.setAge(1);
        student.setName("11");
       Object ob =  transactionTemplate.execute(new TransactionCallback<Object>() {
            @Override
            public Object doInTransaction(TransactionStatus transactionStatus) {
                studentDao.insert(student);
                transactionStatus.setRollbackOnly();
                return "执行完毕";
            }
        });
        return ob;
    }

 

上一篇:spring通过注解注册bean的方式+spring生命周期


下一篇:Python实战网站开发:Day6-编写配置文件