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);
}

dawei

【声明】:唐山站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。