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

问题描述 投票:1回答:1

我在存储库中有一个自定义方法,我想要更改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"

java spring spring-data-rest
1个回答
0
投票

根据Spring Data REST Documentation

All query method resources are exposed under the search resource.

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

© www.soinside.com 2019 - 2024. All rights reserved.