-
Spring boot: pageable, getReferencedId백엔드/spring 2023. 2. 6. 17:14
10개 프로젝트로 완성하는 백엔드 웹개발(Java/Spring) 초격차 패키지 Online. part 2.2.4:게시판 페이지 기능 구현
수강을 하며 기록한 내용입니다.
A.
- map() 을 통해 findAll(pageable)로 찾은 Article 을 ArticleDto로 형변환
- ArticleDto::from을 통해 일종의 mapper 역할을 하는 것.
- 참고:[배워보자 Spring Data JPA] JPA 에서 Pageable 을 이용한 페이징과 정렬 (tistory.com)
B. ArticleServiceTest 의 getReferenceById
- getReferenceById(dto.id);
- sd
C.ArticleService
- 이때 articleRepository.save(article); 은 필요없음
- why?: updateArticle은 class level @Transactional에 의해서 method 단위로 transaction이 묶여있고, transaction이 끝날 때, 영속성 컨텍스트는 article이 변한 것을 감지하고, 그 감지한 것에 대한 query를 날린다. 그래서 update query가 실행되고, 따로 save 문을 할 필요가 없다.
'백엔드 > spring' 카테고리의 다른 글
웹페이지 만들기1 :환경 설정 (0) 2023.02.10 spring "Argument are different!" 해결 (0) 2023.02.09 Spring Security - @WebSecurityConfigurerAdapter 변경(+ spring security dependencies 설정) (0) 2023.02.02 Thymeleaf 와 뷰 템플릿 엔진 원리 (0) 2023.02.02 spring 과 Rest API 에 대해 (0) 2023.02.01