@Override
public Object process(AnnotationInfo ctx, Object value) throws Exception {
if (!ctx.isAnnotationPresent(Min.class)
&& !ctx.isAnnotationPresent(Max.class)) {
return value;
}
long minValue = 1;
if (ctx.isAnnotationPresent(Min.class)) {
minValue = ctx.getAnnotation(Min.class).value();
}
long maxValue = 50;
if (ctx.isAnnotationPresent(Max.class)) {
maxValue = ctx.getAnnotation(Max.class).value();
}
if (Number.class.isAssignableFrom(value.getClass())) {
return range(String.valueOf(minValue), String.valueOf(maxValue), value.getClass());
} else if (value instanceof String) {
String strVal = (String) value;
if (strVal.length() < minValue) {
strVal += RandomStringUtils.randomAlphabetic((int) minValue - strVal.length());
} else if (strVal.length() > maxValue) {
strVal = strVal.substring(0, (int) maxValue);
}
return strVal;
}
return value;
}
MinMaxAnnotationPostProcessor.java 文件源码
java
阅读 21
收藏 0
点赞 0
评论 0
项目:randomito-all
作者:
评论列表
文章目录