10

我已经在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 控制器)?

4

1 回答 1

11

我检查了代码库——似乎他们明确禁用了自定义方法——不知道为什么。这是来自 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);
}
于 2014-02-01T19:30:10.067 回答