JPA select查询与where子句 [英] JPA select query with where clause
本文介绍了JPA select查询与where子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想写一条select语句,但不知道如何写where子句...
I want to write a select statement but can't figure out how to write the where clause...
我的代码:
CriteriaQuery query = entityManager.getCriteriaBuilder().createQuery();
query.select(query.from(SecureMessage.class)).where();
这是在我要向其传递字符串的方法中.我只想获取与Im传递给该方法的字符串的值匹配的行.
This is within a method that I am passing a string to. I want to fetch only the rows that match the value of the string that Im passing to the method.
推荐答案
据我了解,方法参数应该是查询的参数.
As I understand, the method parameter should be the parameter of the query.
因此,应如下所示:
Query query = entityManager.getCriteriaBuilder().createQuery("from SecureMessage sm where sm.someField=:arg1");
query.setParameter("arg1", arg1);
其中arg1
-您的方法String参数
where arg1
- your method String parameter
这篇关于JPA select查询与where子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文