【发布时间】:2018-06-10 12:05:00
【问题描述】:
我有一个这样的实体类:
@Entity
@Table(name = "CUSTOMER")
class Customer{
@Id
@Column(name = "Id")
Long id;
@Column(name = "EMAIL_ID")
String emailId;
@Column(name = "MOBILE")
String mobile;
}
如何使用 crudrepository spring data jpa 为以下查询编写 findBy 方法?
select * from customer where (email, mobile) IN (("a@b.c","8971"), ("e@f.g", "8888"))
我期待类似的东西
List<Customer> findByEmailMobileIn(List<Tuple> tuples);
我想从给定对中获取客户列表
【问题讨论】:
-
我认为你只能这样做
List<Customer> findByEmailInAndMobileIn(List<String> emails, List<String> mobiles); -
这很可悲。你认为我应该在这个用例中使用 spring jdbctemplate 吗?
-
这并不难过,这就是
spring-data的构建方式。您正在给它一个自定义对象,弹簧数据无法弄清楚您的意思。我不确定使用@Query注释并指定您想要的 sql 语句是否适用于您的Tuple类。您必须检查一下。
标签: java spring collections tuples spring-data-jpa