반응형

1. jpql

String jpql = "select a from AccountLog a where ";
if (!vo.getSearchType().equalsIgnoreCase("all"))
jpql += JpqlQueryUtil.getWhereQueryByFileName(vo.getSearchType());

jpql += " a.logTime >= :startDate and a.logTime <= :endDate";

TypedQuery<AccountLog> typedQuery = em.createQuery(jpql, AccountLog.class);

if (!vo.getSearchType().equalsIgnoreCase("all")) {
typedQuery.setParameter("searchWord", vo.getSearchWord());
}

typedQuery.setParameter("startDate", DateUtils.parseDateFormatHHMMSS(vo.getStartDate() + " 00:00:00"));
typedQuery.setParameter("endDate", DateUtils.parseDateFormatHHMMSS(vo.getEndDate() + " 23:59:59"));

result = typedQuery.setFirstResult(vo.getPageNumber() - 1)
				   .setMaxResults(vo.getPageSize())
				   .getResultList();

2. QueryDSL

JPAQuery query = new JPAQuery(em);
QAccountLog accountLog = new QAccountLog("accountLog");

Date startDate = DateUtils.parseDateFormatHHMMSS(vo.getStartDate() + " 00:00:00");
Date endDate = DateUtils.parseDateFormatHHMMSS(vo.getEndDate() + " 23:59:59");

com.querydsl.core.types.Predicate condition = makeWhereQuery(vo, accountLog, startDate, endDate);

FetchableQueryBase queryBase = (FetchableQueryBase) query.from(accountLog)
														.where(condition)
                                                        .limit(vo.getPageSize())
                                                        .offset(vo.getPageNumber() - 1);
                                                                                            
result = queryBase.fetch();
728x90

+ Recent posts