spring - 按示例查询 Spring 数据

标签 spring spring-data query-by-example

我有带日期字段的域对象 Person:

public class Person {
@Id
private Long id;
private Date date

像这样构建示例:

Person person = new Person();
person.setSomeOtherFields("some fields");
Example<Person> example = Example.of(person);

我如何创建具有日期范围的示例查询(搜索实体包含大于或等于某个日期且小于或等于另一个日期的日期)?

最佳答案

Spring Data JPA query-by-example 技术使用 ExampleExampleMatcher 将实体实例转换为底层查询。 current official documentation阐明只有精确匹配可用于非字符串属性。由于您的需求涉及 java.util.Date 字段,您只能通过示例查询技术进行精确匹配。

您可以编写自己的 ExampleMatcher 来根据您的需要返回查询子句。

关于spring - 按示例查询 Spring 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39552467/

相关文章:

java - 使用 Spring boot CrudRepository 过滤数据

java - HibernateTemplate findByExample 不返回任何结果

spring - 为什么从 GroovyTestCase 继承会导致 Grails 2.2 中出现 Spring 错误?

java - 具有超过10个参数的Spring Data Mongo

spring - DispatcherServlet 如何准确地确定要调用哪个 Controller ?

spring - 为什么使用 Spring Data 进行分页查询比普通查询慢?

view - hive 侧 View ,带有带有1列作为阵列的 hive 表的示例示例

Hibernate 示例标准查询 : filtering by child properties

java - Gradle Spring-data-dynamo 数据库

Java - 如何将应急措施构建到调用 Web 服务的服务层中