Hi,在项目中,发现每次都需要校验各种参数。觉得好麻烦,于是就结合实例写了一个自定义的注解,如下:
import java.lang.annotation.*;
/**
* create by zhaojinchao on 2018/8/3
*/
@Target({ElementType.FIELD,ElementType.TYPE,ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface VerifyParam {
boolean isNotNull() default true;
String describe() default "";
}
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.client.HttpClientErrorException;
import java.lang.reflect.Field;
import java.util.List;
/**
* create by zhaojinchao on 2018/8/6
*/
@Slf4j
public class VerifyAnnotationParam {
private Class clazz;
private static VerifyParam verifyParam;
private Object obj;
public VerifyAnnotationParam(Object object) {
clazz =