【问题标题】:Replace query parameters with JSON body in Spring Boot PagingAndSortingRepository在 Spring Boot PagingAndSortingRepository 中用 JSON 正文替换查询参数
【发布时间】:2023-03-12 17:40:01
【问题描述】:

我正在使用 Spring Boot 中的 PagingAndSortingRepository

是否可以从http body(json)接收参数,而不是通过查询参数(@Param)接收。

例子:

@RepositoryRestResource(collectionResourceRel = "people", path = "people")
public interface PersonRepository extends PagingAndSortingRepository<Person, Long> {
  List<Person> findByLastName(@Param("name") String name);
  Person findByUsername(@Param("username") String username);
}

我正在寻找@Param("name") String name 的替代方法,以便从 JSON-Body 而不是查询参数中提取值。

【问题讨论】:

    标签: json spring-boot query-parameters spring-repositories


    【解决方案1】:

    好吧,我的错误是没有深入思考它。使用正文有效负载从 REST 资源中查询数据没有任何意义。

    想想一个用户 (A) 想要与另一位用户 (B) 共享的链接(例如通过电子邮件发送)。查询参数将丢失,因此链接不会从用户的 A 角度代表站点。通过链接共享站点信息的唯一方法是将查询参数附加到链接本身。

    【讨论】:

      猜你喜欢
      • 2021-09-15
      • 2020-10-21
      • 2018-05-03
      • 1970-01-01
      • 2016-12-17
      • 1970-01-01
      • 2020-02-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多