Spring Data JPA“OR"单参数 [英] Spring Data JPA "OR" with single parameter

查看:38
本文介绍了Spring Data JPA“OR"单参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以有这样的 Spring Data JPA 存储库方法:

Is it possible to have a Spring Data JPA repository method like this:

User findByEmailOrUserName(String usernameOrEmail);

上述方法名称不起作用,因为 Spring Data JPA 在尝试查找需要绑定到方法中的第二个属性名称的第二个参数时抛出异常.

The above method name doesn't work as Spring Data JPA throws an exception when it tries to find the second parameter that needs to be bound to second property name in the method.

我想要一个将转换为 select t from User t where t.email = :usernameOrEmail OR t.userName = :usernameOrEmail

方法名查询有这种可能吗?

Does the method name queries have such a possibility?

推荐答案

使用当前最新版本的 Spring Data JPA (v1.10.2),这是不可能的.我也没有看到对未来版本的任何此类请求.

With current latest version of Spring Data JPA (v1.10.2), this is not possible. I don't see any such requests for future versions either.

这篇关于Spring Data JPA“OR"单参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆