Notice
Recent Posts
Recent Comments
Link
DevKim
[JPA] Query 생성 - between method 본문
728x90
docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.repositories
Spring Data JPA - Reference Documentation
Example 109. Using @Transactional at query methods @Transactional(readOnly = true) public interface UserRepository extends JpaRepository { List findByLastname(String lastname); @Modifying @Transactional @Query("delete from User u where u.active = false") v
docs.spring.io
공식 홈에 들어가보면 query를 만드는 method name들이 있다.
그 중에서 24시간 동안만의 데이터를 가져오는 기능을 추가하기 위해 between을 사용해보았다.
*조회를 위한 GetMapping 부분에 하루전과 현재를 repo에 인자로 전달

* LocalDateTime.now( ) : 현재
* LocalDateTime.now( ).minusDays(1) : 하루 전
*Repository에 추가

= ModifiedAt을 기준으로 정렬해줄건데, start와 end의 Between에 있는 것만 Desc(내림차순)으로 정렬해달라는 것
728x90
'Spring Boot' 카테고리의 다른 글
[01] thymeleaf 템플릿 엔진 동작 원리 (0) | 2021.05.06 |
---|---|
+) 인텔리제이 gitbash와 연결, 인텔리제이 안에서 빌드하고 실행하기 (0) | 2021.05.04 |
[Spring] REST API 만들기 (0) | 2021.04.13 |
[Spring] CRUD - H2 DB 웹콘솔로 확인해보기 (0) | 2021.04.13 |
CommandLineRunner,@Bean,@Component (0) | 2021.04.08 |