结合sql表中的2列以搜索全名JPA [英] combine 2 columns in sql table to search for full names JPA
本文介绍了结合sql表中的2列以搜索全名JPA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个实体,其中有fisrtName和lastname,但是在搜索中,我需要实现对fullName的搜索.如何在JPA中将这两个字段组合在一起进行搜索
I have entity where I have fisrtName and lastname but in search I need to implement search for fullName. How can I combine this two fields in search in JPA
现在我有这样的东西:
Query query = em.createQuery("SELECT u from Client u where u.firstName like :firstName or u.lastName like :lastName or u.documentID like :documentID");
我猜这是非常常用的功能,但是我不知道该怎么做.请帮助
I guess it is very commonly used feature but I don't know how to do that. Please help
推荐答案
您尚未定义什么是全名".如果您要串联两个名称"字段,则可以使用JPQL中的构造,例如
You haven't defined what is "full name". If you mean a concatenation of the two "name" fields, then you can use a construct in JPQL such as
CONCAT(u.firstName, ' ', u.lastName)
将它们放在一起并在其之间留有一个空格,应该充分了解如何获取所需的精确查询.
to put them together with a space in between, and that ought to give enough idea how to get the precise query needed.
这篇关于结合sql表中的2列以搜索全名JPA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文