Java – a custom JPA repository method published by spring data rest

I'm already here http://docs.spring.io/spring-data/data-jpa/docs/1.0.x/reference/html/#repositories.custom -Implementation details a custom method to a JPA repository

As far as I can see, this method will not be exposed when I use spring data rest Is there any way to publish it as part of the rest API generated by spring data rest (instead of creating a spring MVC controller yourself)?

Solution

I checked the code base - as if they had explicitly disabled custom methods - and I don't know why Here is org springframework. data. repository. core. support. Relevant code snippet in defaultrepository information

@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);
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>