본문 바로가기
IT/JPA

QueryDSL select specific columns

by 최고영회 2020. 8. 25.
728x90
반응형
SMALL

SELECT all columns 

private final QDoc doc = QDoc.doc; 

@Override public List<Doc> findAll(DocSearch search) {
  return from(doc)
         .where( 
           eqState(search.getStat()),
           eqElucidatorDept(search.getEqDeptName()), 
           ... 
           likeElucidator(search.getElucidator()), 
           likeElucidatorDept(search.getDeptName()) 
          ).fetch(); 
)

Select specific columns (using Tuple)

@Override 
public List<DocDto> findAllForDashboard(DocSearch search) { 
  List<DocDto> rtnList = new ArrayList<>(); List
  <Tuple> list = from(doc) 
                .where( 
                  afterStartDate(search.getStartDate()), 
                  beforeEndDate(search.getEndDate()) 
                ) 
                .select(doc.requestDate, doc.elucidateDate) 
                .fetchResults().getResults(); 
  for (Tuple t : list) { 
    rtnList.add(new DocDto(t.get(0, LocalDateTime.class), t.get(1, LocalDateTime.class))); 
  } 
  return rtnList; 
}
728x90
반응형
LIST