springboot中@Valid注解对Controller层的入参判空

public class Order {
  
      @NotNull(message = "用户ID不能为空")
      private Long userID;
  
      @NotNull(message = "收货人地址id不能为空")
      private Long addressID;
  
      @NotBlank(message = "备注不为空")
      private String comment;
 
 }
 @PostMapping("/createOrders")
    public String createOrders(@RequestBody @Valid Order dto, BindingResult results) { 
         if (results.hasErrors()) 
                return results.getFieldError().getDefaultMessage();
          return "success";
    }

 

你可能感兴趣的:(编程utils)