Search in sources :

Example 1 with ValidateAnnotation

use of com.paascloud.core.annotation.ValidateAnnotation in project paascloud-master by paascloud.

the class UacActionMainController method save.

/**
 * 保存权限信息.
 *
 * @param action the action
 *
 * @return the wrapper
 */
@PostMapping(value = "/save")
@ApiOperation(httpMethod = "POST", value = "新增角色")
@ValidateAnnotation
@LogAnnotation
public Wrapper save(@ApiParam(name = "action", value = "角色信息") @RequestBody UacAction action) {
    LoginAuthDto loginAuthDto = RequestUtil.getLoginUser();
    uacActionService.saveAction(action, loginAuthDto);
    return WrapMapper.ok();
}
Also used : LoginAuthDto(com.paascloud.base.dto.LoginAuthDto) LogAnnotation(com.paascloud.core.annotation.LogAnnotation) ApiOperation(io.swagger.annotations.ApiOperation) ValidateAnnotation(com.paascloud.core.annotation.ValidateAnnotation)

Example 2 with ValidateAnnotation

use of com.paascloud.core.annotation.ValidateAnnotation in project paascloud-master by paascloud.

the class UacRoleMainController method save.

/**
 * 保存用户.
 *
 * @param role the role
 *
 * @return the wrapper
 */
@PostMapping(value = "/save")
@ApiOperation(httpMethod = "POST", value = "新增角色")
@ValidateAnnotation
@LogAnnotation
public Wrapper save(@ApiParam(name = "role", value = "角色信息") @RequestBody UacRole role) {
    LoginAuthDto loginAuthDto = RequestUtil.getLoginUser();
    uacRoleService.saveRole(role, loginAuthDto);
    return WrapMapper.ok();
}
Also used : LoginAuthDto(com.paascloud.base.dto.LoginAuthDto) LogAnnotation(com.paascloud.core.annotation.LogAnnotation) ApiOperation(io.swagger.annotations.ApiOperation) ValidateAnnotation(com.paascloud.core.annotation.ValidateAnnotation)

Example 3 with ValidateAnnotation

use of com.paascloud.core.annotation.ValidateAnnotation in project paascloud-master by paascloud.

the class BindingResultAop method doAfter.

/**
 * Do after.
 *
 * @param joinPoint the join point
 */
@AfterReturning(pointcut = "validateAnnotation()")
public void doAfter(final JoinPoint joinPoint) {
    String methodName = joinPoint.getSignature().getName();
    Object target = joinPoint.getTarget();
    // 得到拦截的方法
    Method method = getMethodByClassAndName(target.getClass(), methodName);
    Object[] objects = joinPoint.getArgs();
    // 方法的参数
    assert method != null;
    ValidateAnnotation annotation = (ValidateAnnotation) getAnnotationByMethod(method, ValidateAnnotation.class);
    if (annotation != null) {
        BindingResult bindingResult = null;
        for (Object arg : objects) {
            if (arg instanceof BindingResult) {
                bindingResult = (BindingResult) arg;
            }
        }
        if (bindingResult != null && bindingResult.hasErrors()) {
            String errorInfo = bindingResult.getFieldError().getDefaultMessage();
            throw new IllegalArgumentException(errorInfo);
        }
    }
}
Also used : BindingResult(org.springframework.validation.BindingResult) Method(java.lang.reflect.Method) ValidateAnnotation(com.paascloud.core.annotation.ValidateAnnotation) AfterReturning(org.aspectj.lang.annotation.AfterReturning)

Aggregations

ValidateAnnotation (com.paascloud.core.annotation.ValidateAnnotation)3 LoginAuthDto (com.paascloud.base.dto.LoginAuthDto)2 LogAnnotation (com.paascloud.core.annotation.LogAnnotation)2 ApiOperation (io.swagger.annotations.ApiOperation)2 Method (java.lang.reflect.Method)1 AfterReturning (org.aspectj.lang.annotation.AfterReturning)1 BindingResult (org.springframework.validation.BindingResult)1