[英]How to query data inserting substring - MYSQL/JPQL
I'm writing the below method on a Java project with Hibernate connecting to the database, and want to know how can I write a query to find a register with just the corrensponding substring. I tried using 'concat' but it didn't work我正在 Java 项目上编写以下方法,其中 Hibernate 连接到数据库,我想知道如何编写查询以查找仅包含相应 substring 的寄存器。我尝试使用“concat”,但它没有用
public List<UnidadeDeSaude> pesquisar(String nome) {
TypedQuery<UnidadeDeSaude> query = manager.createQuery("from UnidadeDeSaude where nomeDoEstabelecimento concat('%',:nomeDoEstabelecimento,'%')", UnidadeDeSaude.class);
query.setParameter("nomeDoEstabelecimento", nome + '%');
return query.getResultList();
}
What you're looking for is LIKE clause你要找的是LIKE 子句
from UnidadeDeSaude where nomeDoEstabelecimento like concat('%',:nomeDoEstabelecimento,'%')", UnidadeDeSaude.class);
And skip the + '%'
from setParameter
并跳过setParameter
中的+ '%'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.