设定范围和步长的递增数验证器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程序版权保护解决方案
通常C.C++等编程语言开发的程序都被编译成目标代码,这些目标代码都是本机器的二进制可执行代码.通常所有的源文件被编译.链接成一个可执行文件.在这些可执行文件中,编译器删除了程序中的变量名称.方法名称 ...
- 1、WWDC2014 详解OSX/iOS8/Swift语言
OS X 10新特性 1.系统图标扁平化. 2.系统菜单栏可定制. 3.新的通知中心. 4.新的Spotlight. 5.新的iCloud Drive,新增文档同步功能(学Windows). 6.新的 ...
- Base-Android快速开发框架(二)--数据存储之SharedPreferences
对于App开发者,抽象来说,其实就是将数据以各种各样的方式展示在用户面前以及采集用户的数据.采集用户的数据包括用户的输入.触摸.传感器等,展示的数据通过网络来源于各业务系统,以及用户的 输入数据.在这 ...
- class0513(html基础加强)
内容:HTML.CSS 目标:掌握手写HTML实现一般难度的Web页面的能力(如网站注册表单),为ASP.Net学习打基础.坚持手写HTML,可视化设计只是一种自学的手段. 参考书:张孝祥<Ja ...
- 2014年25 款最新最棒的jQuery插件
网络上提供了大量非常有用的 jQuery 插件,帮助大家完善网站的体验.所以我们在这里收集了 2014 年发布的,并且是非常有用的插件,希望能帮助大家找到自己需要并且喜欢的,提升网站的质量! HAMM ...
- MapReduce概述,原理,执行过程
MapReduce概述 MapReduce是一种分布式计算模型,运行时不会在一台机器上运行.hadoop是分布式的,它是运行在很多的TaskTracker之上的. 在我们的TaskTracker上面跑 ...
- leetcode@ [307] Range Sum Query - Mutable / 线段树模板
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...
- C++学习笔记(五):指针和引用
声明指针: //指针声明 * 号左右的空格是可选的,下面的定义都是正确的 int *pointer1; int* pointer2; int*pointer3; int * pointer4; //注 ...
- WinFrom 安装包制作
1.添加安装向导项目打开文件系统界面,选择应用程序文件夹.在右侧右击->添加->文件,把程序需要的文件都添加进来. 2.右击程序集->创建快捷方式.右击快捷方式->属性窗口-& ...
- 使用Knoctout.分页
要点:点击标签翻页部分时,pageValue自动加1. 1.api中的方法 public ArticleListModel Get(int page,string _class) { var list ...