springboot中怎么利用自定义注解控制事务回滚
springboot中怎么利用自定义注解控制事务回滚,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

成都创新互联作为成都网站建设公司,专注网站建设公司、网站设计,有关企业网站设计方案、改版、费用等问题,行业涉及LED显示屏等多个领域,已为上千家企业服务,得到了客户的尊重与认可。
springboot 自定义注解通过切面控制方法主动抛异常达到事务回滚的目的
写一个自定义注解
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
public @interface ThrowException {
public String value() default "";
}写一个切面控制,⚠️要用环绕通知
@Aspect
@Component
@Slf4j
public class ThrowExectionAspect implements Ordered {
//service层切点
@Pointcut("@within(com.hasl.isp.policyprovider.annotation.ThrowException)")
public void excetionAspect() {}
@Around("excetionAspect()")
public Object around(ProceedingJoinPoint pjp) throws Throwable {
Object result = pjp.proceed(pjp.getArgs());
if(result != null && result instanceof ReturnMsg) {
ReturnMsg returnMsg = (ReturnMsg)result;
if (returnMsg.getMsgList().size() > 0){
throw new BaseException("业务异常");
}
}
return result;
}
@Override
public int getOrder() {
return Integer.MAX_VALUE;
}
}关于springboot中怎么利用自定义注解控制事务回滚问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注创新互联行业资讯频道了解更多相关知识。
当前名称:springboot中怎么利用自定义注解控制事务回滚
网页路径:http://www.jxjierui.cn/article/geeseh.html


咨询
建站咨询
