본문으로 바로가기

spring data jpa 날짜 between

category Spring/Spring Data JPA 2017.04.27 15:49

1.between 사용법

repository

1
List<LiveBaseballScore> findByLatestUpdateBetween(Date start, Date end);
cs


main.java

1
2
3
4
5
6
7
Date before = new Date(System.currentTimeMillis() - 30000L);
Date now = new Date();
 
System.out.println(before);
System.out.println(now);
 
List<LiveBaseballScore> live = liveBaseballScoreRepository.findByLatestUpdateBetween(before, now);
cs



spring data jpa 메소드 쿼리로 date between만들기



2.between과 and사용법

어제 00:00:00부터 오늘 23:59:59초까지

24:00:00은 데이터 포멧 에러남

1
2
3
4
5
6
7
LocalDateTime startDatetime = LocalDateTime.of(LocalDate.now().minusDays(1), LocalTime.of(0,0,0)); //어제 00:00:00
LocalDateTime endDatetime = LocalDateTime.of(LocalDate.now(), LocalTime.of(23,59,59)); //오늘 23:59:59
 
List<Game> gameList = gameRepository.findBySportsIdAndStartDatetimeBetween(SportsType.BASKETBALL.getCode(),startDatetime, endDatetime);
List<Game> filteredGameList = gameList.stream()
           .filter(game -> game.getStatus() == GameStatus.PROGRESS || game.getStatus() == GameStatus.READY)
           .collect(Collectors.toList());
cs


end.



저작자 표시 비영리
신고

댓글을 달아 주세요