gpt4 book ai didi

java - spring-data-rest 发布的自定义 jpa 存储库方法

转载 作者:IT老高 更新时间:2023-10-28 13:49:47 25 4
gpt4 key购买 nike

我已将自定义方法添加到 jpa 存储库,详细信息请参见 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 Controller )?

最佳答案

我检查了代码库 - 似乎他们明确禁用了自定义方法 - 不知道为什么。这是来自 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);
}

关于java - spring-data-rest 发布的自定义 jpa 存储库方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21116539/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com