Validation

Notice

Only Mongodb Plugin 1.0.5 or higher versions have this function.

Inherit class MongoValidate will inherit automatically class MongoBean.

Usage

Adding Constraints

Firstly let class bean inherit MongoValidate and then adding constraints.

Mongodb Plugin verifier add constrains by annotating variables on the bean object:

@NotNull(message="If message contains text, it can be obtained when faults occuring ")
 private String test;

@AssertTrueFor Boolean field, which could only be true.

@AssertFalseThe value of this field is only false only could be false.

@CreditCardNumberConducting general verification for credit card number.

@DecimalMaxOnly be less than or equal to the value.

@DecimalMinOnly be greater than or equal to the value.

@Digits(integer=2,fraction=20)Check whether it is a numeric integer, fractional, decimal digit.

@EmailCheck whether it is a valid email address.

@FutureCheck whether the date of this field belongs to the future date.

@Length(min=1,max=3)Check whether the length of this field is between min and Max, which only could be used for Strings

@Max(value = 4)The value of this field can only be less than or equal to the value.

@Min(value = 4)The value of this field can only be greater than or equal to the value.

@NotNullCannot be null.

@NotBlankCannot be blank and ignoring space when checking.

@NotEmptyCannot be empty. “Empty” means empty strings.

@NullCheck whether this field is null.

@PastCheck whether the date of this field is in the past.

@Size(min=1, max=3)Check whether this field size is between min and Max, which can be strings, arrays, collections, Map, etc.

@URL(protocol=,host,port)Check whether it is a valid URL. The URL also needs to meet the conditions provided by protocol, host, etc.

@ValidIf this annotation is used, the object contained in the variable will be checked automatically with verifier annotations.

@CreditCardNumber(ignoreNonDigitCharacters=)Check credit card number.

@URL(protocol=, host=, port= regexp=, flags=)Check whether it is a link?

@Type(value=)Checkwhether it is Boolean or int or double. Income it in the value according to the need. Such as value="boolean".

@Inside(value={是否在这个数组(字符串)中Whether in this array (string)

@Inside(value={})Whether in this array (string)

@Chinese(value=boolean)Whether it is Chinese or not. If it is “true”, the variable must be Chinese. If it is “false”, the variable must not be Chinese

@Exist(value=boolean,collectionName=string,key=string)The variable must exist or not in a field of collection in mongodb.If value =true, the variable must exist. If false, it represents non repeatable. If key is "Id" or "_id" , it will automatically convert strings to ObjectId

Start Validation

Directly run “validation ()” to validate:

Account account=new Account() //Inherit Class MongoValidate
account.validation() //Validate all parameters
account.getErrorMessage()  //Get error message, which is to validate the message contents on failed validation comment
account.validation("password", "username") // Only validate certain parameters (1.0.6 version +)

results matching ""

    No results matching ""