设定范围和步长的递增数验证器Validator
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的更多相关文章
- vue props 下有验证器 validator 验证数据返回true false后,false给default值
vue props 下有验证器 validator 验证数据返回true false后,false给default值 props: { type: { validator (value) { retu ...
- 9、 Struts2验证(声明式验证、自定义验证器)
1. 什么是Struts2 验证器 一个健壮的 web 应用程序必须确保用户输入是合法.有效的. Struts2 的输入验证 基于 XWork Validation Framework 的声明式验证: ...
- Hibernate验证器
第 4 章 Hibernate验证器 http://hibernate.org/validator/documentation/getting-started/#applying-constrain ...
- Flask系列09--Flask中WTForms插件,及自定义验证器
一.概述 django中的forms组件非常的方便,在flask中有WTForms的组件实现的也是类似的功能, 安装这个插件 二.简单使用 文档地址https://wtforms.readthedoc ...
- H面试程序(29):求最大递增数
要求:求最大递增数 如:1231123451 输出12345 #include<stdio.h> #include<assert.h> void find(char *s) { ...
- vim中插入递增数
假设生成0-9的递增数 1.插入数字1,yy复制,9p 2.输入命令 let i= | g//s//\=i/ | let i=i+1 3.结果:
- Google Authenticator(谷歌身份验证器)C#版
摘要:Google Authenticator(谷歌身份验证器),是谷歌公司推出的一款动态令牌工具,解决账户使用时遭到的一些不安全的操作进行的"二次验证",认证器基于RFC文档中的 ...
- Flex 内置验证器—验证用户输入
今晚对于Flex中的Validator类(所有验证器的父类)测试一下 ---->其中常用的验证类有StringValidator,NumberValidator,DateValidator 测试 ...
- [Swift]LeetCode591. 标签验证器 | Tag Validator
Given a string representing a code snippet, you need to implement a tag validator to parse the code ...
随机推荐
- 枚举类型的单例模式(java)
Inspired by Effective Java. Singleton模式是在编程实践中应用最广泛的几种设计模式之一.以前知道的,实现单例的方法有两种(下面的A.B).刚刚在读<Effect ...
- LA3942-Remember the Word(Trie)
题意: 有s个不同的单词,给出一个长字符串把这个字符串分解成若干个单词的连接(可重复使用),有多少种分解方法 分析: dp[i]表示i开始的字符串能分解的方法数 dp[i]=sum(dp[i+len( ...
- MSP430F5438点亮led
今天只是想点亮一个led灯,因为没有视频,搞得很多的东西都是自己摸,下午本来讲和咨询店家,TMD说好给一点技术支持,结果一点也不给,我真想草泥马了,其实代码早就写出来了,只是哥哥不知道这款开发板还有接 ...
- -Xms 和 -Xmx 不能设置的太大
之前我一直有一个疑问,就是-Xms 和 -Xmx不是设置的越大越好吗?现在才明白怎么回事. 通过在命令行中执行 java 或者启动某种基于 Java 的中间件来运行 Java 应用程序时,Java 运 ...
- Quartz动态配置表达的方法
在项目中有一个需求,需要灵活配置调度任务时间,并能自由启动或停止调度.有关调度的实现我就第一就想到了Quartz这个开源调度组件,因为很多项目使用过,Spring结合Quartz静态配置调度任务时间, ...
- [原]Java面试题-将字符串中数字提取出来排序后输出
[Title][原]Java面试题-将字符串中数字提取出来排序后输出 [Date]2013-09-15 [Abstract]很简单的面试题,要求现场在纸上写出来. [Keywords]面试.Java. ...
- 计算N的阶层
int factorial(int n) { int i, result; ; i <= n; i++) result *= i; return result; } int factorial2 ...
- NOIP2006 2k进制数
2^k进制数 题目描述 设r是个2^k 进制数,并满足以下条件: (1)r至少是个2位的2^k 进制数. (2)作为2^k 进制数,除最后一位外,r的每一位严格小于它右边相邻的那一位. (3)将r转换 ...
- 利用python进行折线图,直方图和饼图的绘制
我用10个国家某年的GDP来绘图,数据如下: labels = ['USA', 'China', 'India', 'Japan', 'Germany', 'Russia', 'Brazil', ...
- 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 ...