javax.validation.constraints.Max类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(202)

本文整理了Java中javax.validation.constraints.Max类的一些代码示例,展示了Max类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Max类的具体详情如下:
包路径:javax.validation.constraints.Max
类名称:Max

Max介绍

暂无

代码示例

代码示例来源:origin: prontera/spring-cloud-rest-tcc

private static final long serialVersionUID = -7019570768557438079L;
@NotNull
@NotBlank
@Pattern(regexp = "^\\d{11}$", message = "请输入11位手机号")
@JsonProperty("mobile")
@ApiModelProperty(value = "手机号", example = "18888888888", required = true)
private String mobile;
@NotNull
@Size(min = 6, max = 20, message = "请输入6~20位的密码")
@JsonProperty("login_pwd")
@ApiModelProperty(value = "登录与支付密码", example = "123123123", required = true)
private String loginPwd;
@NotNull
@Min(100L)
@Max(100000000L)
@JsonProperty("balance")
@ApiModelProperty(value = "用户的初始化余额", example = "100000000", required = true)
private Long balance;

代码示例来源:origin: swagger-api/swagger-core

if ("integer".equals(property.getType()) || "number".equals(property.getType())) {
  Min min = (Min) annos.get("javax.validation.constraints.Min");
  property.setMinimum(new BigDecimal(min.value()));
if ("integer".equals(property.getType()) || "number".equals(property.getType())) {
  Max max = (Max) annos.get("javax.validation.constraints.Max");
  property.setMaximum(new BigDecimal(max.value()));
Size size = (Size) annos.get("javax.validation.constraints.Size");
if ("integer".equals(property.getType()) || "number".equals(property.getType())) {
  property.setMinimum(new BigDecimal(size.min()));
  property.setMaximum(new BigDecimal(size.max()));
} else if (property instanceof StringSchema) {
  StringSchema sp = (StringSchema) property;
  sp.minLength(new Integer(size.min()));
  sp.maxLength(new Integer(size.max()));
} else if (property instanceof ArraySchema) {
if (property instanceof NumberSchema) {
  NumberSchema ap = (NumberSchema) property;
  ap.setMaximum(new BigDecimal(max.value()));
  ap.setExclusiveMaximum(!max.inclusive());
Pattern pattern = (Pattern) annos.get("javax.validation.constraints.Pattern");
if (property instanceof StringSchema) {
  property.setPattern(pattern.regexp());

代码示例来源:origin: apache/incubator-druid

+ ".javaOptsArray";
@JsonProperty
@NotNull
private String javaCommand = "java";
@JsonProperty
@NotNull
private String javaOpts = "";
@JsonProperty
@NotNull
private List<String> javaOptsArray = ImmutableList.of();
@JsonProperty
@Min(1024)
@Max(65535)
private int startPort = 8100;
@JsonProperty
@Min(1024)
@Max(65535)
private int endPort = 65535;

代码示例来源:origin: apache/incubator-druid

@JsonProperty
@Min(1)
private int segmentsPerNode = 50;
@JsonProperty
@Max(1024 * 1024)
@Min(1024)
private long maxBytesPerNode = 512 * 1024;
@JsonProperty
private boolean skipLoadSpec = false;

代码示例来源:origin: javaee-samples/javaee7-samples

@POST
  @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
  public void post2(@NotNull @FormParam("name") String name, @Min(1) @Max(10) @FormParam("age") int age) {
  }
}

代码示例来源:origin: spring-projects/spring-framework

@NotNull Object myValidMethod(@NotNull(groups = MyGroup.class) String arg1, @Max(10) int arg2);

代码示例来源:origin: org.hibernate.jsr303.tck/jsr303-tck

public class DummyEntity {
  @NotNull
  String foo;
  @Size(min = 5, max = 10, message = "size must be between {min} and {max}")
  String bar;
  @Max(value = 10, message = "{replace.in.user.bundle1}")
  String fubar;
  @NotNull(message = "messages can also be overridden at constraint declaration.")
  String snafu;
}

代码示例来源:origin: org.glassfish.admin/config-api

/**
 * Gets the value of the maxPendingCount property.
 *
 * Max no of pending connections on the listen socket
 * 
 * @return possible object is
 *         {@link String }
 */
@Attribute (defaultValue="4096")
@Min(value=1)
@Max(value=Integer.MAX_VALUE)
String getMaxPendingCount();

代码示例来源:origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests

/**
 * @author Hardy Ferentschik
 */
@GroupSequence({ Minimal.class, A.class })
public class A {
  @Max(value = 10, groups = Minimal.class)
  int size;

  @Size(max = 20)
  String name; //A group
}

代码示例来源:origin: prestodb/presto

@Min(2)
@Max(1000)
public int getMaxOpenSortFiles()
{
  return maxOpenSortFiles;
}

代码示例来源:origin: apache/accumulo

@Template(name = "/default.ftl")
public Map<String,Object> getServerActivity(
  @QueryParam("shape") @DefaultValue("circles") @Pattern(
    regexp = ALPHA_NUM_REGEX_BLANK_OK) String shape,
  @QueryParam("size") @DefaultValue("40") @Min(1) @Max(100) int size,
  @QueryParam("motion") @DefaultValue("") @Pattern(
    regexp = ALPHA_NUM_REGEX_BLANK_OK) String motion,
  @QueryParam("color") @DefaultValue("allavg") @Pattern(
    regexp = ALPHA_NUM_REGEX_BLANK_OK) String color) {

代码示例来源:origin: com.holon-platform.core/holon-core

getValidationMessage(property, a.message(), Validator.ValidationMessage.NOT_NULL)));
  LOGGER.debug(() -> "BeanPropertyBeanValidationPostProcessor: added validator to property ["
      + property + "] for constraint [" + NotNull.class.getName() + "]");
  property.validator(Validator.max(Long.valueOf(a.value()).doubleValue(),
      getValidationMessage(property, a.message(), Validator.ValidationMessage.MAX)));
  LOGGER.debug(
      () -> "BeanPropertyBeanValidationPostProcessor: added validator to property [" + property
          + "] for constraint [" + Max.class.getName() + "] with value [" + a.value() + "]");
});
property.getAnnotation(DecimalMax.class).ifPresent(a -> {
  property.validator(Validator.max(new BigDecimal(a.value()).doubleValue(),
      getValidationMessage(property, a.message(), Validator.ValidationMessage.MAX)));
  LOGGER.debug(() -> "BeanPropertyBeanValidationPostProcessor: added validator to property ["
      + property + "] for constraint [" + DecimalMax.class.getName() + "] with value ["
      + a.value() + "]");
});
  property.validator(Validator.min(Integer.valueOf(a.min()).doubleValue(),
      getValidationMessage(property, a.message(), Validator.ValidationMessage.MIN)));
  property.validator(Validator.max(Integer.valueOf(a.max()).doubleValue(),
  ((Builder) property).validator(Validator.pattern(a.regexp(),
      getValidationMessage(property, a.message(), Validator.ValidationMessage.PATTERN),
      convertPatternFlags(a.flags())));

代码示例来源:origin: com.haulmont.cuba/cuba-global

if (notNull != null) {
  if (isDefinedForDefaultValidationGroup(notNull)) {
    metaProperty.getAnnotations().put(NotNull.class.getName() + VALIDATION_NOTNULL_MESSAGE, notNull.message());
    metaProperty.getAnnotations().put(NotNull.class.getName() + VALIDATION_NOTNULL_MESSAGE, notNull.message());
    metaProperty.getAnnotations().put(NotNull.class.getName() + VALIDATION_NOTNULL_UI_COMPONENT, true);
  metaProperty.getAnnotations().put(Size.class.getName() + VALIDATION_MIN, size.min());
  metaProperty.getAnnotations().put(Size.class.getName() + VALIDATION_MAX, size.max());
  metaProperty.getAnnotations().put(Min.class.getName(), min.value());
  metaProperty.getAnnotations().put(Max.class.getName(), max.value());
  metaProperty.getAnnotations().put(DecimalMax.class.getName(), decimalMax.value());

代码示例来源:origin: hibernate/hibernate-orm

@Column(name = "fld_size")
@Max(10)
public Integer getSize() {
  return size;
}

代码示例来源:origin: primefaces/primefaces

if (constraint.annotationType().equals(Size.class)) {
  Size size = (Size) constraint;
  if (size.max() > 0) {
    setMaxlength(input, size.max());
  spinner.setMax(max.value());
  spinner.setMin(min.value());

代码示例来源:origin: benas/random-beans

maxValue = maxAnnotation.value();
minValue = minAnnotation.value();

代码示例来源:origin: Impetus/Kundera

/**
 * Checks whether a given value is lesser than given max value or not
 * 
 * @param validationObject
 * @param annotate
 * @return
 */
private boolean validateMaxValue(Object validationObject, Annotation annotate)
{
  if (checkNullObject(validationObject))
  {
    return true;
  }
  Long maxValue = ((Max) annotate).value();
  if (checkvalidDigitTypes(validationObject.getClass()))
  {
    if ((NumberUtils.toLong(toString(validationObject))) > maxValue)
    {
      throwValidationException(((Max) annotate).message());
    }
  }
  return true;
}

代码示例来源:origin: com.fasterxml.jackson.module/jackson-module-jsonSchema

@Override
public Double getNumberMaximum(BeanProperty prop) {
  Max maxAnnotation = prop.getAnnotation(Max.class);
  if (maxAnnotation != null) {
    return (double) maxAnnotation.value();
  }
  DecimalMax decimalMaxAnnotation = prop.getAnnotation(DecimalMax.class);
  return decimalMaxAnnotation != null ? new BigDecimal(decimalMaxAnnotation.value()).doubleValue() : null;
}

代码示例来源:origin: hibernate/hibernate-orm

private static void applyMax(Property property, ConstraintDescriptor<?> descriptor, Dialect dialect) {
  if ( Max.class.equals( descriptor.getAnnotation().annotationType() ) ) {
    @SuppressWarnings("unchecked")
    ConstraintDescriptor<Max> maxConstraint = (ConstraintDescriptor<Max>) descriptor;
    long max = maxConstraint.getAnnotation().value();
    @SuppressWarnings("unchecked")
    final Iterator<Selectable> itor = property.getColumnIterator();
    if ( itor.hasNext() ) {
      final Selectable selectable = itor.next();
      if ( Column.class.isInstance( selectable ) ) {
        Column col = (Column) selectable;
        String checkConstraint = col.getQuotedName( dialect ) + "<=" + max;
        applySQLCheck( col, checkConstraint );
      }
    }
  }
}

代码示例来源:origin: org.glassfish.main.common/amx-core

public Long max()
{
  final Max max = mMethod.getAnnotation(Max.class);
  if (max != null)
  {
    return max.value();
  }
  final long[] minMax = minMaxFromDataType(attribute().dataType());
  return minMax == null ? null : minMax[1];
}

相关文章