티스토리 뷰

1.between 사용법

repository

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

 

main.java

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);

 

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

 

 

2.between과 and사용법

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

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

 

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());

 

end.

 

 

728x90
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함