Spring/Spring Data 5

[JPA] 수정은 어떻게 하는 게 좋을까?

여기 블로그 글 엔티티가 있다. @Entity@Getter@NoArgsConstructor(access = AccessLevel.PROTECTED)public class Post { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String title; @Lob private String content; @Builder public Post(String title, String content) { this.title = title; this.content = content; }} 해당 엔티티의 수정에 대한 방식과 각 방식의 장단점을 정리해 ..

Spring/Spring Data 2024.08.20

[JPA] Pageable 페이징 관련 정리

Pageableorg.springframework.data.domain인터페이스이다. 구현체로는 PageRequest, Unpaged 존재 @GetMapping("/posts")public List getList(@PageableDefault Pageable pageable){ return postService.getList(pageable);}클라이언트가 해당 경로(/posts)로 요청을 보내면 설정에 맞게 Pageable 객체를 만들어서 넘겨준다. 페이지 번호는 0부터 시작  YAML 설정 spring: data: web: pageable: one-indexed-parameters: true # 페이지 1부터 시작 default-page-size: 5s..

Spring/Spring Data 2024.08.19

Spring Jpa 쿼리 로그 yaml 설정

spring: jpa: hibernate: ddl-auto: create show-sql: true properties: hibernate: format_sql: true # SQL 보기 좋게 포맷팅 use_sql_comments: true # SQL 내부에 /* */ JPQL 주석 추가logging: level: org.hibernate:SQL: debug # SQL 쿼리 로그 출력 org.hibernate.type.descriptor.sql.BasicBinder: trace # 바인딩된 매개변수 로그 출력  Spring Boot 3.0 이상 사용 시 JPA 쿼리 parameter 로그 설정logging: level: ..

Spring/Spring Data 2024.08.19

로컬 인메모리 H2 데이터베이스 yaml 설정

application.yaml spring: h2: console: enabled: true path: /h2-console datasource: url: jdbc:h2:mem:jeulog username: sa password: driver-class-name: org.h2.Driver spring.h2.console.enabledH2 데이터베이스의 웹 콘솔을 활성화웹 콘솔을 통해 브라우저에서 데이터베이스를 관리하고, SQL 쿼리를 실행 가능 spring.h2.console.pathH2 콘솔에 접근할 수 있는 URL 경로를 지정http://localhost:8080/h2-console로 접속 spring.datasource.urljdbc:h2:mem : ..

Spring/Spring Data 2024.08.19