| | |
| | | import com.google.gson.Gson; |
| | | import com.ks.lib.common.exception.ParamsException; |
| | | import org.aspectj.lang.JoinPoint; |
| | | import org.aspectj.lang.annotation.Aspect; |
| | | import org.aspectj.lang.annotation.Before; |
| | | import org.aspectj.lang.annotation.Pointcut; |
| | | import org.aspectj.lang.reflect.MethodSignature; |
| | | import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator; |
| | | import org.hibernate.validator.resourceloading.PlatformResourceBundleLocator; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.validation.ConstraintViolation; |
| | | import javax.validation.Validation; |
| | |
| | | /** |
| | | * 参数检查AOP |
| | | */ |
| | | @Aspect |
| | | @Component |
| | | public class LuckyParamsCheckAspect { |
| | | private static Validator validator; |
| | | |
| | |
| | | } |
| | | |
| | | @Pointcut("@annotation(org.springframework.validation.annotation.Validated))") |
| | | private void validateMethod() { |
| | | public void validateMethod() { |
| | | } |
| | | |
| | | @Before("validateMethod()") |
| | |
| | | messages.add(error.getMessage()); |
| | | } |
| | | if (!messages.isEmpty()) { |
| | | throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, new Gson().toJson(messages)); |
| | | throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, new Gson().toJson(messages.get(0))); |
| | | } |
| | | } |
| | | |