RestHelper.java 文件源码

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

项目:drinkwater-java 作者:
private static String restPath(Method method, HttpMethod httpMethod) {
    if (httpMethod == HttpMethod.OPTIONS) {
        return "";
    }
    String fromPath = getPathFromAnnotation(method);

    if (fromPath == null || fromPath.isEmpty()) {
        fromPath = List.of(prefixesMap.get(httpMethod))
                .filter(prefix -> method.getName().toLowerCase().startsWith(prefix))
                .map(prefix -> method.getName().replace(prefix, "").toLowerCase())
                .getOrElse("");

        //if still empty
        if (fromPath.isEmpty()) {
            fromPath = method.getName();
        }
    }

    if (httpMethod == HttpMethod.GET) {
        if (fromPath == null || fromPath.isEmpty()) {
            fromPath = javaslang.collection.List.of(method.getParameters())
                    .map(p -> "{" + p.getName() + "}").getOrElse("");
        }
    }

    return fromPath;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号