我在存储库中有一个自定义方法,我想要更改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.
因此,如果您想要自定义行为,则需要编写自己的自定义控制器方法。