类org.hibernate.validator.constraints.Length源码实例Demo

下面列出了怎么用org.hibernate.validator.constraints.Length的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: cuba   文件: DataAwareComponentsTools.java
/**
 * Sets max length for textual UI component using Entity metadata.
 *
 * @param component UI component
 * @param valueSource value source
 */
public void setupMaxLength(TextInputField.MaxLengthLimited component, EntityValueSource valueSource) {
    MetaProperty metaProperty = valueSource.getMetaPropertyPath().getMetaProperty();
    Map<String, Object> annotations = metaProperty.getAnnotations();

    Integer maxLength = (Integer) annotations.get("length");
    if (maxLength != null) {
        component.setMaxLength(maxLength);
    }

    Integer sizeMax = (Integer) annotations.get(Size.class.getName() + "_max");
    if (sizeMax != null) {
        component.setMaxLength(sizeMax);
    }

    Integer lengthMax = (Integer) annotations.get(Length.class.getName() + "_max");
    if (lengthMax != null) {
        component.setMaxLength(lengthMax);
    }
}
 
private void givenFieldDescriptorsWithConstraints() {
    Attribute constraintAttributeWithNotNull = Attributes.key("notImportant").value(singletonList(new Constraint(NotNull.class.getName(), emptyMap())));

    HashMap<String, Object> lengthAttributes = new HashMap<>();
    lengthAttributes.put("min", 2);
    lengthAttributes.put("max", 255);
    Attribute constraintAttributeWithLength = Attributes.key("notImportant").value(singletonList(new Constraint(Length.class.getName(), lengthAttributes)));

    fieldDescriptors =  Arrays.asList(
            fieldWithPath("id").description("some").type(STRING).attributes(constraintAttributeWithNotNull),
            fieldWithPath("lineItems[*].name").description("some").type(STRING).type(STRING).attributes(constraintAttributeWithLength),
            fieldWithPath("lineItems[*]._id").description("some").type(STRING).attributes(constraintAttributeWithNotNull),
            fieldWithPath("lineItems[*].quantity.value").description("some").type(NUMBER).attributes(constraintAttributeWithNotNull),
            fieldWithPath("lineItems[*].quantity.unit").description("some").type(STRING),
            fieldWithPath("shippingAddress").description("some").type(OBJECT),
            fieldWithPath("billingAddress").description("some").type(OBJECT).attributes(constraintAttributeWithNotNull),
            fieldWithPath("billingAddress.firstName").description("some").type(STRING).attributes(Attributes
                    .key("notImportant")
                    .value(singletonList(new Constraint(NotEmpty.class.getName(), emptyMap())))),
            fieldWithPath("billingAddress.valid").description("some").type(BOOLEAN),
            fieldWithPath("paymentLineItem.lineItemTaxes").description("some").type(ARRAY)
    );
}
 
源代码3 项目: mPaaS   文件: FdName.java
/**
 * 读-名称
 *
 * @return
 */
@Length(max = 200)
@NotBlank
@MetaProperty(messageKey = "property.fdName")
default String getFdName() {
    return (String) getExtendProps().get("fdName");
}
 
源代码4 项目: mPass   文件: TreeEntity.java
/**
 * 读-层级ID
 *
 * @return
 */
@MetaProperty(showType = ShowType.NONE, messageKey = "property.fdHierarchyId")
@Length(max = 900)
@Column(columnDefinition = "varchar(900)")
default String getFdHierarchyId() {
    return (String) getExtendProps().get("fdHierarchyId");
}
 
源代码5 项目: WeEvent   文件: RuleDatabaseBase.java
public RuleDatabaseBase(Integer userId, Integer brokerId,
                        @NotBlank String databaseUrl, @NotBlank String username,
                        @NotBlank String password, @NotBlank String datasourceName,
                        @Length(max = 256) String optionalParameter,
                        Boolean systemTag, Integer databaseType) {
    this.userId = userId;
    this.brokerId = brokerId;
    this.databaseUrl = databaseUrl;
    this.username = username;
    this.password = password;
    this.datasourceName = datasourceName;
    this.optionalParameter = optionalParameter;
    this.systemTag = systemTag;
    this.databaseType = databaseType;
}
 
/**
 * ok
 * 方法上的@Validated注解,一般用来指定 验证组
 *
 * @param code
 * @return
 */
@GetMapping("/requestParam/get")
@Validated
public String paramGet(@Length(max = 3)
                       @NotEmpty(message = "不能为空")
                       @RequestParam(value = "code", required = false) String code) {
    return "方法上的@Validated注解,一般用来指定 验证组";
}
 
/**
 * Called when posting the search form on the Zwitscher board.
 *
 * @param q         the query string
 * @param viewModel the view model used to render the template
 * @return the template to use
 */
@RequestMapping(value = "/search", method = RequestMethod.GET)
public String search(@RequestParam("q") @Length(max = 500) String q,
                     Model viewModel) {
    populateDefault(viewModel);
    populateTweets(q, viewModel);
    return "index";
}
 
/**
 * Find the matching Zwitscher messages for the given query.
 *
 * @param q the query, max 500 chars long
 * @return the tweets, never NULL
 */
@HystrixCommand(fallbackMethod = "none")
public Collection<Zwitscher> findByQ(final @Length(max = 500) String q) {
    log.info("Get Zwitscher message from /tweets using q={}.", q);

    Zwitscher[] tweets = restTemplate.getForObject(tweetsRibbonUrl, Zwitscher[].class, q);
    return Arrays.asList(tweets);
}
 
源代码9 项目: Shop-for-JavaWeb   文件: User.java
@Length(min=0, max=100, message="用户类型长度必须介于 1 和 100 之间")
@ExcelField(title="用户类型", align=2, sort=80, dictType="sys_user_type")
public String getUserType() {
	return userType;
}
 
源代码10 项目: Shop-for-JavaWeb   文件: Role.java
@Length(min=1, max=100)
public String getEnname() {
	return enname;
}
 
源代码11 项目: mPaaS   文件: MechanismData.java
/**
 * 读-EntityName
 *
 * @return
 */
@Length(max = 100)
@MetaProperty(messageKey = "property.fdEntityName")
default String getFdEntityName() {
    return (String) getExtendProps().get("fdEntityName");
}
 
源代码12 项目: Shop-for-JavaWeb   文件: Area.java
@Length(min=0, max=100)
public String getCode() {
	return code;
}
 
源代码13 项目: mPaaS   文件: MechanismData.java
/**
 * 读-fdEntityKey
 *
 * @return
 */
@Length(max = 200)
@MetaProperty(messageKey = "property.fdEntityKey")
default String getFdEntityKey() {
    return (String) getExtendProps().get("fdEntityKey");
}
 
源代码14 项目: Shop-for-JavaWeb   文件: Comment.java
@Length(min=1, max=1)
public String getDelFlag() {
	return delFlag;
}
 
源代码15 项目: Shop-for-JavaWeb   文件: User.java
@Length(min=1, max=100, message="工号长度必须介于 1 和 100 之间")
@ExcelField(title="工号", align=2, sort=45)
public String getNo() {
	return no;
}
 
源代码16 项目: Shop-for-JavaWeb   文件: Role.java
@Length(min=1, max=100)
public String getName() {
	return name;
}
 
源代码17 项目: Demo   文件: ValidateOneController.java
/**
 * 普通参数校验
 * @param name
 * @return
 */
@GetMapping("/name")
public String findStudentByName(@NotBlank(message = "学生名字不能为空")
@Length(min = 2, max = 10, message = "name 长度必须在 {min} - {max} 之间")String name){
    return "success";
}
 
源代码18 项目: Shop-for-JavaWeb   文件: Menu.java
@Length(min=0, max=200)
public String getPermission() {
	return permission;
}
 
源代码19 项目: Shop-for-JavaWeb   文件: Menu.java
@Length(min=0, max=100)
public String getIcon() {
	return icon;
}
 
源代码20 项目: Shop-for-JavaWeb   文件: Guestbook.java
@Length(min=1, max=100)
public String getType() {
	return type;
}
 
源代码21 项目: frpMgr   文件: Frp.java
@Length(min=0, max=64, message="项目名称长度不能超过 64 个字符")
public String getProjectName() {
	return projectName;
}
 
源代码22 项目: Shop-for-JavaWeb   文件: Office.java
@Length(min=0, max=200)
public String getPhone() {
	return phone;
}
 
源代码23 项目: Shop-for-JavaWeb   文件: TreeEntity.java
@Length(min=1, max=100)
public String getName() {
	return name;
}
 
源代码24 项目: frpMgr   文件: FrpServer.java
@Length(min=0, max=32, message="域名长度不能超过 32 个字符")
public String getSubdomainHost() {
	return subdomainHost;
}
 
源代码25 项目: Shop-for-JavaWeb   文件: Office.java
@Length(min=1, max=1)
public String getType() {
	return type;
}
 
源代码26 项目: frpMgr   文件: FrpServer.java
@Length(min=0, max=255, message="服务器名称长度不能超过 255 个字符")
public String getServerName() {
	return serverName;
}
 
源代码27 项目: frpMgr   文件: Post.java
@NotBlank(message="岗位名称不能为空")
@Length(min=0, max=100, message="岗位名称长度不能超过 100 个字符")
public String getPostName() {
	return postName;
}
 
源代码28 项目: Shop-for-JavaWeb   文件: Office.java
@Length(min=0, max=200)
public String getEmail() {
	return email;
}
 
源代码29 项目: frpMgr   文件: Company.java
@NotBlank(message="公司名称不能为空")
@Length(min=0, max=200, message="公司名称长度不能超过 200 个字符")
public String getCompanyName() {
	return companyName;
}
 
源代码30 项目: Shop-for-JavaWeb   文件: Dict.java
@XmlAttribute
@Length(min=0, max=100)
public String getDescription() {
	return description;
}
 
 类所在包
 同包方法