【问题标题】:Possible to use @RepositoryRestResource with @PathVariable instead of @Param?可以将@RepositoryRestResource 与@PathVariable 一起使用而不是@Param?
【发布时间】:2015-02-21 23:13:25
【问题描述】:

我有一个正常工作的 RestRepositoryResource。但是,我更喜欢使用路径变量而不是查询参数来构造 URL。目标是这样的:

http://localhost/persons/findByLastName/Smith/

而不是这个:

http://localhost/persons/findByLastName?lastName=Smith

我玩过各种注释,但没有使用 RestRepositoryResource 实现这一点。这是可能的还是必须通过控制器资源映射来完成?

【问题讨论】:

    标签: spring rest spring-data-rest


    【解决方案1】:

    Spring 数据存储库目前不支持 @PathVariable 注释。然而,解决此问题的一个简单解决方法可能是使用URLRewriteFilter 在内部将http://localhost/persons/findByLastName/Smith/ 的请求重新路由到http://localhost/persons/findByLastName?lastName=Smith,而不会引起用户注意。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-06
      • 2015-08-21
      • 2015-11-28
      • 2011-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多