小编mar*_*cin的帖子

将提供的queryDSL谓词与预定义查询结合

在Spring Data REST的上下文中,我想针对单个查询的结果公开搜索/过滤器功能。如果我的查询是findAll,那将是开箱即用的(足以扩展QueryDslPredicateExecutor)。但是,如何将自定义查询(findMyNotes)与用户提供的其他过滤功能(标记为已完成)结合起来。我的意思是:

@Entity
class Note {
    @Id
    private UUID id;
    private UUID personId;
    private String status;
    private String text;
}

@RepositoryRestResource(path = "notes", itemResourceRel = "notes", collectionResourceRel = "notes")
interface NoteRepository extends JpaRepository<Note, UUID>, QueryDslPredicateExecutor<Note> {

    @RestResource(path="notes/my")
    @Query("select n from Note n where n.personId=:creatorId")
    Page<Note> findDone(@Param("creatorId") UUID creatorId, Predicate predicate, Pageable pageable);
}
Run Code Online (Sandbox Code Playgroud)

我什么也没发现。因此,我在考虑使用AOP和:

  1. 有多个路径(多个@RestResource?)映射到org.springframework.data.querydsl.QueryDslPredicateExecutor#findAll(Predicate, org.springframework.data.domain.Pageable)
  2. 有我自己的注释,它将使我指向返回原始queryDSL谓词的方法(@Query示例中的内容)
  3. 通过AOP计算这两个谓词的AND,并将其作为参数传递给findAll方法

问题是我不知道如何做第一点(除了在servlet过滤器中将其黑客化)-将多个路径映射到同一个findAll方法。

或者,也许我错过了一些开箱即用的功能?

spring spring-data-rest

5
推荐指数
0
解决办法
368
查看次数

标签 统计

spring ×1

spring-data-rest ×1