반응형
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
'[개발관련] > JAVA' 카테고리의 다른 글
[프로그래머스] 큰수만들기 (0) | 2021.09.22 |
---|---|
[JAVA] hash개념, HashSet과 HashMap비교 (0) | 2021.05.21 |
XXE injection 취약코드 Spring xml 파일업로드 (0) | 2020.06.24 |
[JAVA] StringTokenizer 클래스 (0) | 2019.11.25 |
MyBatis - org.apache.ibatis.executor.ExecutorException: Executor was closed. (0) | 2019.05.06 |