简体   繁体   中英

how get record from db before given date in JPA

public List<Trans> findByDate(Date date1) {
    Query query = em.createQuery("SELECT k FROM Trans WHERE k.transDate= :transDate ORDER BY k.transDate")
            .setParameter("transDate", date1);
    return query.getResultList();
}

that is part of my code in jpa, how if i want to check if there are records in 'Trans' table with transDate before date1?
thank you

use the '<' operator

public List<Trans> findByDate(Date date1) {
    Query query = em.createQuery("SELECT k FROM Trans WHERE k.transDate < :transDate ORDER BY k.transDate")
            .setParameter("transDate", date1);
    return query.getResultList();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM