org.hibernate.validator.constraints.Length Java Examples

The following examples show how to use org.hibernate.validator.constraints.Length. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: cuba   Author: cuba-platform   File: DataAwareComponentsTools.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example #2
Source Project: restdocs-raml   Author: ePages-de   File: JsonSchemaFromFieldDescriptorsGeneratorTest.java    License: MIT License 6 votes vote down vote up
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)
    );
}
 
Example #3
Source Project: mPaaS   Author: lihangqi   File: FdName.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 读-名称
 *
 * @return
 */
@Length(max = 200)
@NotBlank
@MetaProperty(messageKey = "property.fdName")
default String getFdName() {
    return (String) getExtendProps().get("fdName");
}
 
Example #4
Source Project: mPass   Author: tiankong0310   File: TreeEntity.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 读-层级ID
 *
 * @return
 */
@MetaProperty(showType = ShowType.NONE, messageKey = "property.fdHierarchyId")
@Length(max = 900)
@Column(columnDefinition = "varchar(900)")
default String getFdHierarchyId() {
    return (String) getExtendProps().get("fdHierarchyId");
}
 
Example #5
Source Project: WeEvent   Author: WeBankFinTech   File: RuleDatabaseBase.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #6
Source Project: zuihou-admin-cloud   Author: zuihou   File: HibernateValidateController.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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注解,一般用来指定 验证组";
}
 
Example #7
Source Project: cloud-native-zwitscher   Author: qaware   File: ZwitscherBoardController.java    License: MIT License 5 votes vote down vote up
/**
 * 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";
}
 
Example #8
Source Project: cloud-native-zwitscher   Author: qaware   File: ZwitscherRepository.java    License: MIT License 5 votes vote down vote up
/**
 * 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);
}
 
Example #9
Source Project: Shop-for-JavaWeb   Author: EleTeam   File: User.java    License: MIT License 4 votes vote down vote up
@Length(min=0, max=100, message="用户类型长度必须介于 1 和 100 之间")
@ExcelField(title="用户类型", align=2, sort=80, dictType="sys_user_type")
public String getUserType() {
	return userType;
}
 
Example #10
Source Project: Shop-for-JavaWeb   Author: EleTeam   File: Role.java    License: MIT License 4 votes vote down vote up
@Length(min=1, max=100)
public String getEnname() {
	return enname;
}
 
Example #11
Source Project: mPaaS   Author: lihangqi   File: MechanismData.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 读-EntityName
 *
 * @return
 */
@Length(max = 100)
@MetaProperty(messageKey = "property.fdEntityName")
default String getFdEntityName() {
    return (String) getExtendProps().get("fdEntityName");
}
 
Example #12
Source Project: Shop-for-JavaWeb   Author: EleTeam   File: Area.java    License: MIT License 4 votes vote down vote up
@Length(min=0, max=100)
public String getCode() {
	return code;
}
 
Example #13
Source Project: mPaaS   Author: lihangqi   File: MechanismData.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 读-fdEntityKey
 *
 * @return
 */
@Length(max = 200)
@MetaProperty(messageKey = "property.fdEntityKey")
default String getFdEntityKey() {
    return (String) getExtendProps().get("fdEntityKey");
}
 
Example #14
Source Project: Shop-for-JavaWeb   Author: EleTeam   File: Comment.java    License: MIT License 4 votes vote down vote up
@Length(min=1, max=1)
public String getDelFlag() {
	return delFlag;
}
 
Example #15
Source Project: Shop-for-JavaWeb   Author: EleTeam   File: User.java    License: MIT License 4 votes vote down vote up
@Length(min=1, max=100, message="工号长度必须介于 1 和 100 之间")
@ExcelField(title="工号", align=2, sort=45)
public String getNo() {
	return no;
}
 
Example #16
Source Project: Shop-for-JavaWeb   Author: EleTeam   File: Role.java    License: MIT License 4 votes vote down vote up
@Length(min=1, max=100)
public String getName() {
	return name;
}
 
Example #17
Source Project: Demo   Author: turoDog   File: ValidateOneController.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 普通参数校验
 * @param name
 * @return
 */
@GetMapping("/name")
public String findStudentByName(@NotBlank(message = "学生名字不能为空")
@Length(min = 2, max = 10, message = "name 长度必须在 {min} - {max} 之间")String name){
    return "success";
}
 
Example #18
Source Project: Shop-for-JavaWeb   Author: EleTeam   File: Menu.java    License: MIT License 4 votes vote down vote up
@Length(min=0, max=200)
public String getPermission() {
	return permission;
}
 
Example #19
Source Project: Shop-for-JavaWeb   Author: EleTeam   File: Menu.java    License: MIT License 4 votes vote down vote up
@Length(min=0, max=100)
public String getIcon() {
	return icon;
}
 
Example #20
Source Project: Shop-for-JavaWeb   Author: EleTeam   File: Guestbook.java    License: MIT License 4 votes vote down vote up
@Length(min=1, max=100)
public String getType() {
	return type;
}
 
Example #21
Source Project: frpMgr   Author: Zo3i   File: Frp.java    License: MIT License 4 votes vote down vote up
@Length(min=0, max=64, message="项目名称长度不能超过 64 个字符")
public String getProjectName() {
	return projectName;
}
 
Example #22
Source Project: Shop-for-JavaWeb   Author: EleTeam   File: Office.java    License: MIT License 4 votes vote down vote up
@Length(min=0, max=200)
public String getPhone() {
	return phone;
}
 
Example #23
Source Project: Shop-for-JavaWeb   Author: EleTeam   File: TreeEntity.java    License: MIT License 4 votes vote down vote up
@Length(min=1, max=100)
public String getName() {
	return name;
}
 
Example #24
Source Project: frpMgr   Author: Zo3i   File: FrpServer.java    License: MIT License 4 votes vote down vote up
@Length(min=0, max=32, message="域名长度不能超过 32 个字符")
public String getSubdomainHost() {
	return subdomainHost;
}
 
Example #25
Source Project: Shop-for-JavaWeb   Author: EleTeam   File: Office.java    License: MIT License 4 votes vote down vote up
@Length(min=1, max=1)
public String getType() {
	return type;
}
 
Example #26
Source Project: frpMgr   Author: Zo3i   File: FrpServer.java    License: MIT License 4 votes vote down vote up
@Length(min=0, max=255, message="服务器名称长度不能超过 255 个字符")
public String getServerName() {
	return serverName;
}
 
Example #27
Source Project: frpMgr   Author: Zo3i   File: Post.java    License: MIT License 4 votes vote down vote up
@NotBlank(message="岗位名称不能为空")
@Length(min=0, max=100, message="岗位名称长度不能超过 100 个字符")
public String getPostName() {
	return postName;
}
 
Example #28
Source Project: Shop-for-JavaWeb   Author: EleTeam   File: Office.java    License: MIT License 4 votes vote down vote up
@Length(min=0, max=200)
public String getEmail() {
	return email;
}
 
Example #29
Source Project: frpMgr   Author: Zo3i   File: Company.java    License: MIT License 4 votes vote down vote up
@NotBlank(message="公司名称不能为空")
@Length(min=0, max=200, message="公司名称长度不能超过 200 个字符")
public String getCompanyName() {
	return companyName;
}
 
Example #30
Source Project: Shop-for-JavaWeb   Author: EleTeam   File: Dict.java    License: MIT License 4 votes vote down vote up
@XmlAttribute
@Length(min=0, max=100)
public String getDescription() {
	return description;
}