java中的前台传入参数检验_java项目参数校验神器parameter-check

原标题:java项目参数校验神器parameter-check

e5136cc2dc48d0c387a52235d3630f38.png

3e41a298e2b60f5f9ac27392e22c575f.png

还在为冗长的参数校验而写if else吗?还在用hibernae.validator单一场景的参数校验器吗?那你就out了,java最新注解参数校验器,一次注解,到处使用,引入timing的概念,可以随时随地随心所欲地使用参数校验,方便快捷,高效省时,安全可靠,再也不用写简单而又复杂的参数校验啦!

github地址(帮忙star):https://github.com/Anyzm/parameter-check

maven坐标:

com.github.anyzm

parameter-starter

0.0.1-RELEASE

简单示例:

##1、spring project demo##

```

package com.example.demo;

import cn.anyzm.parameter.annotation.AssertBoolean;

import cn.anyzm.parameter.annotation.NotNull;

import cn.anyzm.parameter.annotation.Range;

import lombok.Data;

/**

* @author huangzhaolai-jk

* @version 1.0.0

* @Deion Student is used for

* @Date 2020/07/12 - 18:43

*/

@Data

public class Student {

@NotNull(timing = "123")

private String name;

@Range(minValue = 1,maxValue = 18,msg = "年龄必须是1-18岁",timing = "456")

private int age = 0;

@AssertBoolean(timing = "789",value = false)

private boolean flag = false;

}

public static void main(String[] args) throws Exception {

Student student = new Student;

student.setAge(0);

student.setFlag(true);

ParameterCheckHandler.checkFiled(student);

ParameterCheckHandler.checkFiled(student,"789");

}

```

ParameterCheckHandler.checkFiled has overload method,use timing by yourself,verify all the timing without timing input。

##2、spring-boot project demo##

```

package com.example.demo;

import cn.anyzm.parameter.annotation.Verify;

import org.springframework.web.bind.annotation.RequestBody;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**

* @Author ZhaoLai Huang

* created by ZhaoLai Huang on 2020/7/25

*/

@RestController

public class TestController {

@RequestMapping("/test")

@Verify

public String test(@Verify @RequestBody Student student) {

System.out.println(student);

return "ok";

}

}

```

add @Verify on your method,and add @Verify before your parameter,you can use it with timing。if the parameter is the Basic types or String,you can directly use @NotNull,@NotEmpty and so on。

cf13f6e5cab243f4f1c9d278323d61c0.png

2020/08/05

参数校验一直是项目中一块简单而又繁琐的工作,parameter-check转为java项目准备,将你从逻辑简单实现繁琐的参数校验中解脱出来

责任编辑:

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值