MinMaxAnnotationPostProcessor.java 文件源码

java
阅读 25 收藏 0 点赞 0 评论 0

项目:randomito-all 作者:
@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;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号