【发布时间】:2019-05-22 08:41:56
【问题描述】:
我在 Spring Boot 中有一个查询: 我正在使用 CrudRepository,我需要为项目中使用的条件的所有可能组合声明方法名称。我们可以在 CrudRepository 中声明一个可以接受动态 where 条件的方法吗?
假设我有一个名为“Student”的表,它有 20 列。我不想在 CrudRepository 中为这 20 个字段定义所有可能的方法名称组合。我需要一个通用方法,它可以接受一个 json 对象作为参数,并根据作为 json 对象传递的 where 条件返回记录。有什么解决方案或解决方法吗?
【问题讨论】:
-
您可以在 StudentRepository 接口中定义 StudentCustomeRepository 接口并扩展 CrudRepository 和 StudentCustomeRepository。第二步,您将在 StudentCustomeRepositoryImpl 中使用 CriteriaBuilder
-
或使用 querydsl core.extensions.queryds
标签: spring spring-boot