find and Between two dates with query by Example<S> JP



我现在就在我的jparerepository上做这个,我喜欢它的工作方式,它是多么容易与其他实体复制

<S extends MyObject> Page<S> findAll(Example<S> example, Pageable pageRequest);

现在我想要相同的格式与示例,但能够找到2个日期之间,是可能的没有@查询?

<S extends MyObject> Page<S> findByDateBetween(Date startDate, Date endDate, Example<S> example, Pageable pageRequest);

https://docs.spring.io/spring-data/jpa/docs/current/reference/html/查询//目前,只有SingularAttribute属性可以用于属性匹配

编辑:经过一番研究我认为唯一的方法是做一个自定义查询,我不喜欢这种方法,因为Example<S> example类有很多属性。

EDIT2:https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/repository/query/FluentQuery.FetchableFluentQuery.htmlFluentJPA似乎是一个很好的归档方式,我没有看到实现这种类型的函数的方法

是的,spring JPA有方法findAllByPublicationTimeBetween()它检索在给定的两个小时内发表的文章。

参考:[https://www.baeldung.com/spring-data-jpa-query-by-date]

相关内容

最新更新