背景介绍
在spring中可以使用@Transactional
注解去控制事务,当出现异常时会进行回滚,在多线程中,这个注解则不会生效,如果主线程需要先执行一些修改数据库的操作,当子线程在进行处理出现异常时,主线程修改的数据则不会回滚,导致数据错误!
示例
package com.smallrig.wms.pick.controller;
import com.smallrig.wms.pick.entity.WmsHeadPicketTicket;
import com.smallrig.wms.pick.entity.WmsHeadPicketTicketLog;
import com.smallrig.wms.pick.mapper.WmsHeadPicketTicketLogMapper;
import com.smallrig.wms.pick.mapper.WmsHeadPicketTicketMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestControlle