SPRControllerEndpoint.java 文件源码

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

项目:homunculus 作者:
@Nullable
@Override
public AnnotatedMethod process(Method method) {
    RequestMapping named = method.getAnnotation(RequestMapping.class);
    if (named != null) {
        Class[] parameterTypes = Reflection.getParameterTypes(method);
        String[] parameterNames = new String[parameterTypes.length];
        String name = "";
        if (named.value().length > 0) {
            name = named.value()[0];
        } else {
            name = method.getName();
        }
        AnnotatedMethod res = new AnnotatedMethod(method, name, parameterTypes, parameterNames);
        Annotation[][] declaredParameterAnnotations = Reflection.getParameterAnnotations(method);
        NEXT_PARAM:
        for (int i = 0; i < declaredParameterAnnotations.length; i++) {
            Annotation[] annotations = declaredParameterAnnotations[i];
            for (Annotation annotation : annotations) {
                if (annotation instanceof RequestParam) {
                    String pName = ((RequestParam) annotation).value();
                    parameterNames[i] = pName;
                    continue NEXT_PARAM;
                }
            }
            //if we come here, no annotation was found -> not good!
            LoggerFactory.getLogger(method.getDeclaringClass()).error("{}.{}: {}. Parameter is unnamed and may cause invocation failure at runtime ", method.getDeclaringClass().getSimpleName(), res, i);
        }
        return res;
    }
    return null;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号