롯데ON 커뮤니티 게시판은 공지사항, 자유게시판, 자료실 등 다양한 카테고리로 나뉘며,
사용자는 제목, 내용, 작성자 기준으로 검색할 수 있습니다.
QueryDSL을 활용해 검색 조건을 동적으로 조립하고, 카테고리별 검색 URL을 통해
검색 기능을 명확하게 분리했습니다.
Community1Controller@GetMapping("/Community/searchFree")
public String searchFree(PageRequestDTO pageRequestDTO, Model model) {
log.info("pageRequestDTO:{}", pageRequestDTO);
PageResponseDTO pageResponseDTO = communityService.searchAll(pageRequestDTO);
log.info("pageResponseDTO:{}", pageResponseDTO);
model.addAttribute(pageResponseDTO);
return "/Community/search/searchFree";
}
PageRequestDTO에 검색 조건(keyword, searchType)과 페이지 정보를 전달searchAll()을 호출하여 결과를 받아 View에 전달Community1Service.searchAll()public PageResponseDTO searchAll(PageRequestDTO pageRequestDTO) {
Pageable pageable = pageRequestDTO.getPageable("no");
Page<Tuple> pageCommunity = communityRepository1.selectAllForSearch(pageRequestDTO, pageable);
List<Community1DTO> communityDTOList = pageCommunity.getContent().stream().map(tuple -> {
Community1 community = tuple.get(0, Community1.class);
String name = tuple.get(1, String.class);
Community1DTO communityDTO = modelMapper.map(community, Community1DTO.class);
communityDTO.setName(name);
return communityDTO;
}).toList();
int total = (int) pageCommunity.getTotalElements();
return PageResponseDTO.<Community1DTO>builder()
.pageRequestDTO(pageRequestDTO)
.dtoList(communityDTOList)
.total(total)
.build();
}
PageRequestDTO)를 바탕으로 QueryDSL 쿼리를 수행