java - What to use spring Restcontroller or RepositoryRestResource
问题描述
I need produce Rest Api with spring HAL hateoas support and pagination. What I see is if I use @Restcontroller I need manually write code for _links and paging logic.
If I use RepositoryRestResource we can get generated links and pagination but I don't have control on _link generation and API path, I don't know I can customize or not.
So how can we use @restcontroller and RepositoryRestResource together so that I can use pagination of repository rest resource and API path of rest controller
解决方案
您可以继续在您的存储库上使用@RepositoryRestResource,按照要点实现您所提到的,
- 使用org.springframework.data.repository.PagingAndSortingRepository扩展您的存储库,它将提供分页内容,您只需在请求参数中传递页面和大小即可完成该工作。
- 可以在存储库中定义的方法之上使用 @RestResource(path = "your_path_to_api") 自定义 API 路径。
推荐阅读
- c# - 货币汇率表显示错误符号
- linux - 共享内存给出模棱两可的结果
- css - 动画不适用于 ReactJS 中的组件。
- java - 错误:找到了很久,而需要数组
- android - 由 ResourceNotFoundException 引起的类 NavigationView 膨胀错误
- delphi - 如何从对象存储库中删除表单
- javascript - Javascript中for ... of循环和执行上下文中的解构赋值
- apache-spark - 如何使用 Spark 对象获取 Hive 表的位置值?
- java - 我如何从列中获取价值?(爪哇)
- visual-studio-code - VS Code - 将这些推荐的设置粘贴到您的工作区设置中