@NotNull 返回对应message

添加ExceptionHandler:

    @ExceptionHandler(MethodArgumentNotValidException.class)
    public BaseResMessage handleArgumentNotValidException(MethodArgumentNotValidException e) {
      return new BaseResMessage().error204Return(e.getBindingResult().getFieldError().getDefaultMessage());
    }

添加@Valid

    @PostMapping("/auto")
    public BaseResMessage<AutoAuditOrderDTO> auto(@RequestBody @Valid AutoAuditDetialRequest request){
      return otherService.autoAuditDetail(request.getOrderId());
    }

添加@NotNull

@Data
public class AutoAuditDetialRequest implements Serializable {
  @NotNull(message = "订单id不为空")
  private Long orderId;
}
posted @ 2019-12-26 09:23  huanghaunghui  阅读(4124)  评论(0编辑  收藏  举报