java validate 框架_ZValidate 基于SpringMVC的参数校验框架

ZValidate

基础SpringMVC的参数校验框架

使用方式:

添加pom依赖

org.zvalidate

org-zvalidate

1.0.0

springMVC配置拦截器如下:

控制器直接添加注解:

@Controller

@RequestMapping("/ValidateTest")

public class TestCtr {

@RequestMapping("/Phone")

@ResponseBody

public String Phone(@Phone String phone){

return phone;

}

@RequestMapping("/IDCard")

@ResponseBody

public String IDCard(@IDCard String idcard){

return idcard;

}

@RequestMapping("/EMail")

@ResponseBody

public String EMail(@Email String email){

return email;

}

@RequestMapping("/SqlInject")

@ResponseBody

public String TestValidate(@SqlInject String sql){

return sql;

}

@RequestMapping("/Custom")

@ResponseBody

public String Custom(@Custom String custom){

return custom;

}

}

添加自定义注解实现方式:

第一步:定义注解

@Target(ElementType.PARAMETER)

@Retention(RetentionPolicy.RUNTIME)

@Documented

public @interface Custom {

}

第二步:实现Algorithms接口:

public class CustomAlgorithms implements Algorithms{

//必须实现固定格式ALGORITHMS_HASH_MAP.put(Custom.class,this.getClass());

public void addAlgorithmsAnnotationMap() {

ALGORITHMS_HASH_MAP.put(Custom.class,this.getClass());

}

//必须实现固定格式customAnnotations.add(Custom.class);

public void addAlgorithmsAnnotationList() {

customAnnotations.add(Custom.class);

}

//参数校验具体算法

public String Validate(String s) {

if(s.equals("custom")){

return VALIDATE_STATUS;

}

return "Custom ERROR";

}

}

#

此框架供于学习使用,切不可用于生产环境哦

😯!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值