1:在实体类上加上注解

/**
     * 产品名称
     */
    @TableField("product_name")
    @NotBlank
    private String productName;

2:service的校验方法

@Override
    public void validationOrderRelationshipNotice(OrderRelationshipNotice orderRelationshipNotice) throws ValidationException{
        //校验参数是否为空
        Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
        Set<ConstraintViolation<OrderRelationshipNotice>> constraintViolations = validator.validate(orderRelationshipNotice);
        List<ConstraintViolation<OrderRelationshipNotice>> list = new ArrayList(constraintViolations);
        if (!CollectionUtils.isEmpty(list)) {
            ConstraintViolation<OrderRelationshipNotice> constraintViolation = list.get(0);
            if (constraintViolation != null) {
                throw new ValidationException(constraintViolation.getMessage());
            }
        }
    }

 

相关文章:

  • 2022-12-23
  • 2021-09-27
  • 2021-12-20
  • 2021-07-15
  • 2022-12-23
  • 2021-07-03
  • 2022-12-23
  • 2021-12-29
猜你喜欢
  • 2022-12-23
  • 2021-09-03
  • 2022-12-23
  • 2021-05-23
  • 2019-12-05
相关资源
相似解决方案