My pojo
public class PacketData implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private final String token = UUID.randomUUID().toString();
private final ZonedDateTime arrived = ZonedDateTime.now();
}
I plan to use like following.
@Query("?")
List<PacketData> findPacketArrivedBetween(ZonedDateTime startDate, ZonedDateTime endDate);
Is there a way i can put the following query to the above query
annotation and how i can do greater than and less than logic
Query query = new Query().addCriteria(Criteria.where("arrived").gte(startDate).lte(endDate));
You can try following couple of ways.
Without Query Annotation.
List<PacketData> findByArrivedBetween(ZonedDateTime startDate, ZonedDateTime endDate);
With Query Annotation.
@Query("{'arrived': {$gte: ?0, $lte:?1 }}")
List<PacketData> findPacketArrivedBetween(ZonedDateTime startDate, ZonedDateTime endDate);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With