diff --git a/代码库/mall-admin/src/main/java/com/sock/mall/component/BIndingResultAspect.java b/代码库/mall-admin/src/main/java/com/sock/mall/component/BIndingResultAspect.java new file mode 100644 index 0000000..e40d3bd --- /dev/null +++ b/代码库/mall-admin/src/main/java/com/sock/mall/component/BIndingResultAspect.java @@ -0,0 +1,44 @@ +package com.macro.mall.component; + +import com.macro.mall.dto.CommonResult; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; +import org.springframework.validation.BindingResult; + +/** + * HibernateValidator + * Created by macro on 2018/4/26. + */ +@Aspect +@Component +@Order(2) +public class BindingResultAspect { + @Pointcut("execution(public * com.macro.mall.controller.*.*(..))") + /*SpringMVCIJ֤*/ + /*Spring֤Ĵ󷵻BindingResult*/ + public void BindingResult() { + } + + @Around("BindingResult()") + public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { + /*Around(value="BindingResult()"*/ + Object[] args = joinPoint.getArgs(); + for (Object arg : args) { + if (arg instanceof BindingResult) { + /*֤ͨ*/ + BindingResult result = (BindingResult) arg; + if (result.hasErrors()) { + /*ݲ*/ + return new CommonResult().validateFailed(result); + /* ֤ͨ쳣*/ + /*شļϢ*/ + } + } + } + return joinPoint.proceed();//AOPл֪ͨproceed + } +}