2024/08/19 5

[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

MockMvc

MockMvc?Spring Framework 에서 제공하는 테스트 유틸리티Spring MVC 웹 애플리케이션의 컨트롤러 계층을 테스트하기 위해 사용실제 웹 서버를 실행하지 않고도 컨트롤러에 대한 요청과 응답을 시뮬레이션해당 기능을 통해 빠르고 효율적으로 웹 애플리케이션 기능을 검증 가능MockMvc 주요 기능 애플리케이션 컨텍스트 사용MockMvc는 스프링 애플리케이션 컨텍스트 내에서 작동스프링 빈 및 의존성 주입, 보안 설정 등 스프링의 다양한 기능 테스트 가능다양한 HTTP 요청 시뮬레이션MockMvc는 GET, POST, PUT, DELETE 등의 다양한 HTTP 요청을 시뮬레이션이 가능요청의 헤더, 본문, 파라미터 등을 설정할 수 있다.응답 검증 응답의 상태 코드, 헤더 본문 등의 내용을 쉽게 검..

Spring/Spring MVC 2024.08.19