java – 由spring-data-rest发布的自定义jpa仓库方法

前端之家收集整理的这篇文章主要介绍了java – 由spring-data-rest发布的自定义jpa仓库方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经在 http://docs.spring.io/spring-data/data-jpa/docs/1.0.x/reference/html/#repositories.custom-implementations中详细介绍了一个自定义方法到一个jpa仓库

据我所见,当我使用spring-data-rest时,这种方法不会暴露出来.有没有什么办法可以发布它作为由spring-data-rest生成的REST API的一部分(不自己创建一个Spring MVC控制器)?

解决方法

我检查了代码库 – 似乎他们已经明确禁用自定义方法 – 不知道为什么.以下是org.springframework.data.repository.core.support.DefaultRepositoryInformation中的相关代码
@Override
public Set<Method> getQueryMethods() {

    Set<Method> result = new HashSet<Method>();

    for (Method method : getRepositoryInterface().getMethods()) {
        method = ClassUtils.getMostSpecificMethod(method,getRepositoryInterface());
        if (isQueryMethodCandidate(method)) {
            result.add(method);
        }
    }

    return Collections.unmodifiableSet(result);
}

/**
 * Checks whether the given method is a query method candidate.
 * 
 * @param method
 * @return
 */
private boolean isQueryMethodCandidate(Method method) {
    return isQueryAnnotationPresentOn(method) || !isCustomMethod(method) && !isBaseClassMethod(method);
}
原文链接:https://www.f2er.com/java/124997.html

猜你在找的Java相关文章