1、接口注释

  1. @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER})
  2. @Retention(RUNTIME)
  3. @Documented
  4. @Constraint(validatedBy = {IncrementalValidator.class})
  5. public @interface IncrementalInteger {
  6.  
  7. String message() default "{common.incrementalInteger.Pattern}";
  8.  
  9. Class<?>[] groups() default {};
  10.  
  11. Class<? extends Payload>[] payload() default {};
  12.  
  13. /**
  14. * @return value the element must be larger or equal to
  15. */
  16. int min();
  17.  
  18. /**
  19. * @return value the element must be smaller or equal to
  20. */
  21. int max();
  22.  
  23. /**
  24. * @return value must be incremental
  25. */
  26. int increment();
  27.  
  28. /**
  29. * Defines several {@link IncrementalInteger} annotations on the same
  30. * element.
  31. *
  32. * @see IncrementalInteger
  33. */
  34. @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER})
  35. @Retention(RUNTIME)
  36. @Documented
  37. @interface List {
  38.  
  39. IncrementalInteger[] value();
  40. }
  41. }

2、Validator类

  1. public class IncrementalValidator implements ConstraintValidator<IncrementalInteger, Integer> {
  2.  
  3. private IncrementalInteger constraintAnnotation;
  4.  
  5. @Override
  6. public void initialize(IncrementalInteger constraintAnnotation) {
  7. this.constraintAnnotation = constraintAnnotation;
  8. }
  9.  
  10. @Override
  11. public boolean isValid(Integer value, ConstraintValidatorContext context) {
  12. int min = constraintAnnotation.min();
  13. int increment = constraintAnnotation.increment();
  14. int max = constraintAnnotation.max();
  15. if (value < min) {
  16. return false;
  17. }
  18.  
  19. if (value > max) {
  20. return false;
  21. }
  22.  
  23. if ((value - min) % increment != 0) {
  24. return false;
  25. }
  26.  
  27. return true;
  28. }
  29. }

设定范围和步长的递增数验证器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. 枚举类型的单例模式(java)

    Inspired by Effective Java. Singleton模式是在编程实践中应用最广泛的几种设计模式之一.以前知道的,实现单例的方法有两种(下面的A.B).刚刚在读<Effect ...

  2. LA3942-Remember the Word(Trie)

    题意: 有s个不同的单词,给出一个长字符串把这个字符串分解成若干个单词的连接(可重复使用),有多少种分解方法 分析: dp[i]表示i开始的字符串能分解的方法数 dp[i]=sum(dp[i+len( ...

  3. MSP430F5438点亮led

    今天只是想点亮一个led灯,因为没有视频,搞得很多的东西都是自己摸,下午本来讲和咨询店家,TMD说好给一点技术支持,结果一点也不给,我真想草泥马了,其实代码早就写出来了,只是哥哥不知道这款开发板还有接 ...

  4. -Xms 和 -Xmx 不能设置的太大

    之前我一直有一个疑问,就是-Xms 和 -Xmx不是设置的越大越好吗?现在才明白怎么回事. 通过在命令行中执行 java 或者启动某种基于 Java 的中间件来运行 Java 应用程序时,Java 运 ...

  5. Quartz动态配置表达的方法

    在项目中有一个需求,需要灵活配置调度任务时间,并能自由启动或停止调度.有关调度的实现我就第一就想到了Quartz这个开源调度组件,因为很多项目使用过,Spring结合Quartz静态配置调度任务时间, ...

  6. [原]Java面试题-将字符串中数字提取出来排序后输出

    [Title][原]Java面试题-将字符串中数字提取出来排序后输出 [Date]2013-09-15 [Abstract]很简单的面试题,要求现场在纸上写出来. [Keywords]面试.Java. ...

  7. 计算N的阶层

    int factorial(int n) { int i, result; ; i <= n; i++) result *= i; return result; } int factorial2 ...

  8. NOIP2006 2k进制数

    2^k进制数 题目描述 设r是个2^k 进制数,并满足以下条件: (1)r至少是个2位的2^k 进制数. (2)作为2^k 进制数,除最后一位外,r的每一位严格小于它右边相邻的那一位. (3)将r转换 ...

  9. 利用python进行折线图,直方图和饼图的绘制

    我用10个国家某年的GDP来绘图,数据如下: labels   = ['USA', 'China', 'India', 'Japan', 'Germany', 'Russia', 'Brazil', ...

  10. leetcode@ [236] Lowest Common Ancestor of a Binary Tree(Tree)

    https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/ Given a binary tree, find the ...