How to pass parameter on jpa query?

痴心易碎 提交于 2019-12-06 06:23:05

You haven't explained the JPA relationship between SmsIn and SmsOut, so I'll assume SmsOut has a getSmsIn() with a relation on the id field.

When you have an EntityManager em, you can call em.createQuery, which is like SQL prepare, and then setParameter:

TypedQuery<SmsOut> q = em.createQuery("SELECT so FROM SmsOut so WHERE so.smsIn.mobileNumber = :number ORDER BY id DESC");
q.setParameter("number", "12345678");
List<SmsOut> results = q.getResultList();

See the Javadoc for Query for the different ways you can specify the parameters.

SELECT so FROM SmsOut so WHERE smsIn.mobileNumber = ? AND smsIn.smsText =? order by id desc

Replace the ? sign with the apropiate values.

between is the problem:

between so.smsOutDate =:startDate and so.smsOutDate =:endDate 

try

so.smsOutDate between  =:startDate and =:endDate 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!