如何通过特定字段过滤PanacheQuery ?



我想排序,筛选和页面PanacheQuery:

@GET
public Response listAllPaged(@BeanParam PagedRequest req) {
// Sorting
PanacheQuery<MyEntity> all = MyEntity.findAll(Sort.by(req.sortBy, Sort.Direction.Ascending));

// Filtering
[...] ? I want to keep only results where req.filterBy == req.filterValue

// Paging
List<MyDTO> list = all
.page(Page.of(pagedRequest.pageNum, pagedRequest.pageSize))
.stream()
.map(myMapper::toDto)
.collect(Collectors.toList());
return Response.ok().entity(new PagedResponse<>(all.count(), list)).build();
}

PanacheQuery有一个.filter()方法,但据我所知,这是用于预定义的Hibernate过滤器。

我想用字段值对过滤我的结果,像这样:

all.filter("status", "alive")
all.filter("age", "25")

我找不到很多关于如何实现这一点的例子,夸克的文档在这个主题上相当安静。有什么建议吗?

由于Panache不支持JPA标准/谓词,我最终自己构建查询,就像这里一样。

最新更新