1、接口注释

@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER})
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = {IncrementalValidator.class})
public @interface IncrementalInteger { String message() default "{common.incrementalInteger.Pattern}"; Class<?>[] groups() default {}; Class<? extends Payload>[] payload() default {}; /**
* @return value the element must be larger or equal to
*/
int min(); /**
* @return value the element must be smaller or equal to
*/
int max(); /**
* @return value must be incremental
*/
int increment(); /**
* Defines several {@link IncrementalInteger} annotations on the same
* element.
*
* @see IncrementalInteger
*/
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER})
@Retention(RUNTIME)
@Documented
@interface List { IncrementalInteger[] value();
}
}

2、Validator类

public class IncrementalValidator implements ConstraintValidator<IncrementalInteger, Integer> {

    private IncrementalInteger constraintAnnotation;

    @Override
public void initialize(IncrementalInteger constraintAnnotation) {
this.constraintAnnotation = constraintAnnotation;
} @Override
public boolean isValid(Integer value, ConstraintValidatorContext context) {
int min = constraintAnnotation.min();
int increment = constraintAnnotation.increment();
int max = constraintAnnotation.max();
if (value < min) {
return false;
} if (value > max) {
return false;
} if ((value - min) % increment != 0) {
return false;
} return true;
}
}

设定范围和步长的递增数验证器Validator的更多相关文章

  1. vue props 下有验证器 validator 验证数据返回true false后,false给default值

    vue props 下有验证器 validator 验证数据返回true false后,false给default值 props: { type: { validator (value) { retu ...

  2. 9、 Struts2验证(声明式验证、自定义验证器)

    1. 什么是Struts2 验证器 一个健壮的 web 应用程序必须确保用户输入是合法.有效的. Struts2 的输入验证 基于 XWork Validation Framework 的声明式验证: ...

  3. Hibernate验证器

    第 4 章 Hibernate验证器  http://hibernate.org/validator/documentation/getting-started/#applying-constrain ...

  4. Flask系列09--Flask中WTForms插件,及自定义验证器

    一.概述 django中的forms组件非常的方便,在flask中有WTForms的组件实现的也是类似的功能, 安装这个插件 二.简单使用 文档地址https://wtforms.readthedoc ...

  5. H面试程序(29):求最大递增数

    要求:求最大递增数 如:1231123451 输出12345 #include<stdio.h> #include<assert.h> void find(char *s) { ...

  6. vim中插入递增数

    假设生成0-9的递增数 1.插入数字1,yy复制,9p 2.输入命令 let i= | g//s//\=i/ | let i=i+1 3.结果:

  7. Google Authenticator(谷歌身份验证器)C#版

    摘要:Google Authenticator(谷歌身份验证器),是谷歌公司推出的一款动态令牌工具,解决账户使用时遭到的一些不安全的操作进行的"二次验证",认证器基于RFC文档中的 ...

  8. Flex 内置验证器—验证用户输入

    今晚对于Flex中的Validator类(所有验证器的父类)测试一下 ---->其中常用的验证类有StringValidator,NumberValidator,DateValidator 测试 ...

  9. [Swift]LeetCode591. 标签验证器 | Tag Validator

    Given a string representing a code snippet, you need to implement a tag validator to parse the code ...

随机推荐

  1. ArcGIS 读写lyr层文件

    原文arcengine C# 读写lyr(转) 写lyr IFeatureLayer LineLayer = axMapControl1.get_Layer() as IFeatureLayer; I ...

  2. HDU 1024 Max Sum Plus Plus 简单DP

    这题的意思就是取m个连续的区间,使它们的和最大,下面就是建立状态转移方程 dp[i][j]表示已经有 i 个区间,最后一个区间的末尾是a[j] 那么dp[i][j]=max(dp[i][j-1]+a[ ...

  3. hive的使用和深化理解

    1.hive中的数据最终是存放在hdfs上的 2.hive本身不是关系型数据库,hive执行sql语句时会把sql语句翻译成mapreduce程序,然后将mapreduce程序提交到hadoop集群中 ...

  4. 使用 EasyBCD 安装Ubuntu 14.04 Error 15: file not found错误的解决方法

    今天安装Window7 和 Ubuntu 14.04 双系统时,出现如下异常,记录一下. 安装过程是参考 http://www.linuxidc.com/Linux/2014-04/100369.ht ...

  5. uvalive 4992 Jungle Outpost

    题意:一个凸边型,目标在凸边型内且最优.问最多删除几个点使目标暴露在新凸边型外面. 思路:二分+半平面相交. #include<cstdio> #include<cmath> ...

  6. Android--应用开发2(AndroidManfest.xml)

    AndroidManfest.xml 文件分析 manifest 根节点,描述package中所有内容 xmlns:android 包含命名空间声明.xmlns:android="http: ...

  7. 100+经典Java面试题及答案解析

    面向对象编程(OOP) Java是一个支持并发.基于类和面向对象的计算机编程语言.下面列出了面向对象软件开发的优点: 代码开发模块化,更易维护和修改. 代码复用. 增强代码的可靠性和灵活性. 增加代码 ...

  8. RecyclerView使用笔记

    1.判断是否可以滑动 //是否可以上滑 ViewCompat.canScrollVertically(recyclerView, 1); //是否可以下滑 ViewCompat.canScrollVe ...

  9. A Tour of Go Function closures

    Go functions may be closures. A closure is a function value that references variables from outside i ...

  10. python 定义函数

    在Python中,定义一个函数要使用def语句,依次写出函数名.括号.括号中的参数和冒号:,然后,在缩进块中编写函数体,函数的返回值用return语句返回. 我们以自定义一个求绝对值的my_abs函数 ...