首页 > 解决方案 > 为 findAllByTypeAndCreatedAtAfter() mongodb 方法添加最大大小限制和方向

问题描述

是否可以制定一个像下面这样返回 List 的查询方法1)of max size n

包含的 Appliance 对象是2) createdAfter a specific time (Instant) at DESC order,

3) they are of a specific TypeEnum。我已经确定了1st2nd要求,但是

我还没有找到如何添加max sizedirection限制。

<T extends Appliance> List<T> findAllByTypeAndCreatedAtAfter(ApplianceTypeEnum applianceTypeEnum);

标签: javaspringmongodbspring-bootjava-8

解决方案


你可以这样做:

<T extends Appliance> List<T> findFirst3ByTypeAndCreatedAtAfterDesc(ApplianceTypeEnum applianceTypeEnum);

您可以在此处阅读有关 Spring 派生查询的更多信息


推荐阅读