/** * Created by 12274 on 2018/8/29. * 實現類全部方法入參校驗 */ @Aspect @Component @Slf4j public class AopServiceImplConfig { @Pointcut("execution(public * cn.primeledger.bitun.boss.biz.api.*.*(..))") public void paramValidate(){ } @Before("paramValidate()") public void before(JoinPoint joinPoint) throws Throwable { //參數數組 不可能爲空,若是沒有參數->{},若是參數爲null->{null} Object[] paramArray = joinPoint.getArgs(); log.info("class={},methon name={},methon param={}",joinPoint.getSignature().getName(),paramArray); //判斷參數數組是否爲null if (paramArray != null && paramArray.length > 0){ try{ for (Object obj : paramArray) { BeanValidator.validate(obj).failThrow(); } }catch (Exception e){ throw new BossParamsException(e.getMessage()); } } } }