其他分享
首页 > 其他分享> > springboot 使用mybatis的事务操作

springboot 使用mybatis的事务操作

作者:互联网

使用很简单,只需要在service层对应方法上注解@Transactional即可。

package com.wxl.go.service.impl;

import com.wxl.go.dao.PersonDao;
import com.wxl.go.model.Person;
import com.wxl.go.service.PersonService;
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 PersonServiceImpl implements PersonService {
    @Autowired
    private PersonDao personDao;

    @Override
    public List<Person> selectAll() {
        return personDao.selectAll();
    }

    @Override
    @Transactional
    public Integer updatePerson(Person person) {
        person.setAge(100);
        personDao.updatePerson(person);
        int k = 1 / 0;
        person.setId(1);
        personDao.updatePerson(person);
        return 1;
    }

}

标签:personDao,事务,springboot,person,go,wxl,mybatis,import,com
来源: https://blog.csdn.net/qq_50909707/article/details/123204455