java - 如何在@RestResource 中将“路径”设为空以使端点仅作为 /search{?name}
问题描述
我在存储库中有一个自定义方法,我想更改 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文档。
All query method resources are exposed under the search resource.
因此,如果您想要自定义行为,则需要编写自己的自定义控制器方法。
推荐阅读
- hadoop - 生产级 Hive 和 Sqoop 配置
- android - 如何使用毕加索从 json 解析图像 base64 和 jpeg
- html - 引导图像背景以覆盖容器内的整个宽度
- c - 为什么在这种情况下linux系统调用“capset”失败?
- .net - 找不到工具包参考(System.Windows.Controls.Input.Toolkit & System.Windows.Controls.Toolkit)
- reactjs - webpack dev不断抱怨组件无效
- angular - 为 Angular5 添加组件时出错
- pandas - 每次遇到值时切片数据帧
- bash - jq解析中如何使用环境变量参数
- python - 通过给定的折扣策略获取折扣列表并续订月份