SpringHateOAS和querydsl:如何在json响应中记录查询参数?

5gfr0r5j  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(226)

我创建了一个带有querydsl过滤的hateoas restapi。
使用的依赖项:

在代码中,我有以下内容:

  1. @GetMapping(produces = {"application/hal+json"})
  2. @PageableAsQueryParam
  3. public ResponseEntity<PagedModel<ItemModel>> findItems(
  4. @QuerydslPredicate(root = Item.class) Predicate predicate,
  5. @Parameter(hidden = true) Pageable pageable) {
  6. log.info("Items retrieved");
  7. Page<Item> allItems = itemService.findAll(predicate, pageable);
  8. return itemsToResponse(allItems);
  9. }

用这个 @QuerydslPredicate 注解,可以这样过滤项 /?name=First&age=30 .
但是在haljson响应中,我想宣布哪些属性(比如 name 以及 age 在本例中)可用于过滤。
例如:

  1. {
  2. "links": [
  3. {
  4. "rel": "items",
  5. "href": "/items{?name,age}"
  6. }
  7. ]
  8. }

有没有可能用查询dsl自动生成?或者,如果必须手动构建,我将如何构建这样的链接?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题