加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-14 16:32:50 所属栏目:Java 来源:网络整理
导读:我已经在 http://docs.spring.io/spring-data/data-jpa/docs/1.0.x/reference/html/#repositories.custom-implementations中详细介绍了一个自定义方法到一个jpa仓库 据我所见,当我使用spring-data-rest时,这种方法不会暴露出来.有没有什么办法可以发布它作为
我已经在 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);
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读