jeecgboot @Transactional捕获异常并拿到返回值

2023-05-16

@Transactional   和  @RestControllerAdvice  并不冲突

回滚的同时拦截异常返回需要的值给前端

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public String save(Data data) {
        try{
            dao.insert(data);
        } catch( JeecgBootException e){
            throw new JeecgBootException("插入数据失败!");
        }
        return "true";
    }

/**
 * 异常处理器
 * 
 * @Author scott
 * @Date 2019
 */
@RestControllerAdvice
@Slf4j
public class JeecgBootExceptionHandler {

	/**
	 * 处理自定义异常
	 */
	@ExceptionHandler(JeecgBootException.class)
	public Result<?> handleRRException(JeecgBootException e){
		log.error(e.getMessage(), e);
		return Result.error(e.getMessage());
	}
}

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

jeecgboot @Transactional捕获异常并拿到返回值 的相关文章

随机推荐