gpt4 book ai didi

java - 如何在 @RestResource 中将 'path' 设置为空,以使端点仅作为/search{?name}

转载 作者:太空宇宙 更新时间:2023-11-04 09:45:48 25 4
gpt4 key购买 nike

我在存储库中有一个自定义方法,我想更改 Spring 生成的端点。需要忽略“/search”之后的“路径”

当前下面是正在公开的端点 (/search/findByName{?name})。

 "customFind": {
"href": "http://localhost:8080/productType/search/findByName{?name}",
"templated": true
}

当前代码:

@RepositoryRestResource(collectionResourceRel = "productType", path = "productType")
public interface ProductTypeRepository extends JpaRepository<ProductType, Long> {

@RestResource(path ="findByName", rel = "customFind")
ProductType findByNameIgnoreCase(@Param("name") String productTypeName);

}

需要更改“路径”,以便我想要访问我的端点,如下所示。

 "customFind": {
"href": "http://localhost:8080/productType/search{?name}",
"templated": true
}

我尝试指定path="",但没有任何效果。

我希望最终的终点是这样的http://localhost:8080/productType/search?name="wooden"

最佳答案

根据 Spring Data REST Documentation .

All query method resources are exposed under the search resource.

因此,如果您想要自定义行为,您需要编写自己的自定义 Controller 方法。

关于java - 如何在 @RestResource 中将 'path' 设置为空,以使端点仅作为/search{?name},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55443893/

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