全局异常拦截Controller
@RestControllerAdvice
public class UserExceptionTranslator {
private static final Logger logger = LoggerFactory.getLogger(UserExceptionTranslator.class);
private final ObjectMapper objectMapper = new ObjectMapper();
/** * @param ex * @Description: 参数校验 * @Author: Mr.Zhong * @Date: 2019-09-13 21:26 */ @ExceptionHandler(MethodArgumentNotValidException.class) public LinkResponse validationBodyException(MethodArgumentNotValidException ex) { BindingResult result = ex.getBindingResult(); return LinkResponse.builder().baseResponse(999999, result.getFieldError().getDefaultMessage()).build(); }
}
接参对象@Validated 注解一定要添加否则不会进行校验
@ApiOperation("修改支付密码前置数据")
@PostMapping(value = "/account/password/update.do")
public Result updatePassword(@Validated @RequestBody ModifyPayPasswordDTO request) {
bizAccountService.updatePayPassword(RequestUserContext.getRequestUserId(), request.getValidCode(), request.getNewPayPassword());
return Result.success();
}
@Data
@ApiModel("修改支付密码")
public class ModifyPayPasswordDTO {
@NotBlank(message = "新支付密码不能为空")
private String newPayPassword;
@NotBlank(message = "短信验证码不能为空")
private String validCode;
}