spring-data-rest 发布的自定义 jpa 存储库方法 [英] Custom jpa repository method published by spring-data-rest

查看:27
本文介绍了spring-data-rest 发布的自定义 jpa 存储库方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将自定义方法添加到 jpa 存储库中,详见 http://docs.spring.io/spring-data/data-jpa/docs/1.0.x/reference/html/#repositories.custom-implementations

I've added a custom method to a jpa repository as detailed on http://docs.spring.io/spring-data/data-jpa/docs/1.0.x/reference/html/#repositories.custom-implementations

据我所知,这个方法在我使用 spring-data-rest 的时候没有暴露出来.有什么办法可以将它发布为 spring-data-rest 生成的 REST API 的一部分(无需自己创建 Spring MVC 控制器)?

As far as I could see, this method is not exposed when I use spring-data-rest. Is there any way I could publish it as part of the REST API generated by spring-data-rest (without creating a Spring MVC Controller myself)?

推荐答案

我检查了代码库 - 似乎他们已经明确禁用了自定义方法 - 不知道为什么.这是来自 org.springframework.data.repository.core.support.DefaultRepositoryInformation

I checked the code base - seems like they have explicitily disabled custom methods - not sure why. Here is the relevant piece of code from 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);
}

这篇关于spring-data-rest 发布的自定义 jpa 存储库方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆