From f55b864c67fb9155e114ef1d378697efe7fc3d4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E7=9A=93=E9=9B=AF?= <18868469283@qq.com> Date: Wed, 9 Jan 2019 12:44:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mall/component/BIndingResultAspect.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 代码库/mall-admin/src/main/java/com/sock/mall/component/BIndingResultAspect.java 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 + } +}