HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
🚀
Random Bit Flip
/
🐶
[2기 - 흑구] 9주차 RBF
🐶

[2기 - 흑구] 9주차 RBF

주차
SpringBoot Part5
회고일
May 20, 2022
참여자
멘토
Property
tag
문정현
[JPA] N+1 문제 원인 및 해결방법 알아보기
N + 1 문제는 성능에 큰 영향을 줄 수 있기 때문에 N + 1 문제가 무엇이고 어떤 상황에 발생되는지, 어떻게 해결하면 되는지에 대해 알아보고자 한다. N + 1문제란 1번의 쿼리를 날렸을 때 의도하지 않은 N번의 쿼리가 추가적으로 실행되는 것을 의미한다. When 언제 발생하는가?
[JPA] N+1 문제 원인 및 해결방법 알아보기
https://dev-coco.tistory.com/165
[JPA] N+1 문제 원인 및 해결방법 알아보기
'📌ETC/Tech Interview' 카테고리의 글 목록
'📌ETC/Tech Interview' 카테고리의 글 목록
'📌ETC/Tech Interview' 카테고리의 글 목록
https://dev-coco.tistory.com/category/%F0%9F%93%8CETC/Tech%20Interview
'📌ETC/Tech Interview' 카테고리의 글 목록
url-shortener
Shortening Url Service Design
bit.ly, ow.ly, short.io 긴 url을 짧게 만들어 준다. 짧은 url을 browser에 붙이면 긴 url로 redirection 시킨다. 장치별 link를 최적화 가능하다. 접근 url의 history를 분석가능하다. AD에 해당 url을 붙임으로써 AD의 효용성을 분석할 수 있다. 긴 url을 짧고 unique하게 url로 제공 가능해야 한다. 충분히 복사 붙여넣기 등이 쉽게 될 수 있는 짧은 길이로 제공해야한다.
Shortening Url Service Design
https://enumclass.tistory.com/212#toc-Load%20Balancer
Shortening Url Service Design
동료 코드 리뷰
JoinColumn의 name, referencedColumnName
영속성 컨텍스트와 트랜잭션 범위
autoIncrement와 seqence의 차이
What is the difference between Oracle's "sequence" and MySql's Auto_increment feature?
A sequence is a distinct database object in Oracle. In MySQL, when you have an autoincrement column and you INSERT a new row in a table, you simply don't mention the autoincrement column and MySQL puts it there. You can then insert the same number into another table by referencing LAST_INSERT_ID().
What is the difference between Oracle's "sequence" and MySql's Auto_increment feature?
https://stackoverflow.com/questions/27867980/what-is-the-difference-between-oracles-sequence-and-mysqls-auto-increment-fe
What is the difference between Oracle's "sequence" and MySql's Auto_increment feature?
게시판 흑구님 피드
  1. AOP 사용해보기 → @AspectJ를 사용해서 controller의 결과를 json으로 파싱하는 어드바이스를 작성해보기
    1. [Spring Boot] REST API 게시판 서버 만들기 #3(Response 커스텀 객체, Exception 처리, ExceptionHandler)
      프로젝트 구조 설명 configuration 패키지 생성. - response 구조를 커스텀할 클래스들 생성. 1. RestResponse : 200 코드를 반환할 때 사용 2. ErrorResponse : 에러 발생시 사용 configuration.aspect 패키지 - RestControllerAspect 클래스 : RestController 역할의 클래스를 감싸는 역할. - ServiceExceptionAspect : 서비스 로직에서 발생하는 에러를 모두 잡는 역할.
      [Spring Boot] REST API 게시판 서버 만들기 #3(Response 커스텀 객체, Exception 처리, ExceptionHandler)
      https://sas-study.tistory.com/282
      [Spring Boot] REST API 게시판 서버 만들기 #3(Response 커스텀 객체, Exception 처리, ExceptionHandler)
      Spring에서 AOP를 사용해보자.
      한 어플리케이션의 여러부분에 걸쳐 있는 기능을 가리켜 횡단관심사(cross-cutting concerns) 라 한다. 주로 로깅이나 세션처리등이 있다. 이런 로깅이나 세션처리작업은 각 모듈에서 반복적으로 사용되고 있으므로 스프링에서는 이러한 것을 AOP(Aspect-Oriented Programming)를 통해 처리하고 있다. 따라서 AOP 의 주된 목적은 횡단관심사의 모듈화에 있다. 즉, 여러모듈에 걸쳐 사용하는 로깅처리나 세션처리등을 별도의 모듈로 분리해서 처리하는 것이다.
      https://yookeun.github.io/java/2014/10/01/spring-aop/
      @Aspect @Component public class ResponseAop { @Around("execution(* com.example.springbootboardjpa.controller.*.*(..))") public ApiResponse<Object> responseString(ProceedingJoinPoint joinPoint) throws Throwable { return ApiResponse.ok(joinPoint.proceed()); } } ... @RestController @RequestMapping("api/v1/posts") public class PostRestController { @Autowired PostService postService; @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public Object create(@RequestBody @Valid PostDto postDto) { long result = postService.create(postDto); return Long.toString(result); } }
  1. RestControllerAdvice, ExceptionHandler 로 처리하기
  1. Dto의 필드는 Wrapper Class로 하기(입력값이 없었다는 걸 확실하게 표현할 수 있음)
  1. Dto나 Entity에 대한 Bean Validation 사용하기
  1. statusCode는 HttpStatus를 사용하는 방식으로 사용
public class ApiResponse<T> { private int statusCode; private T data; @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Seoul") private LocalDateTime serverDatetime; public ApiResponse(HttpStatus status, T data) { //입력은 HttpStatus로 받고 response로 내보낼 때는 value를 이용해서 변환하기 this.statusCode = status.value(); this.data = data; this.serverDatetime = LocalDateTime.now(); } public static <T> ApiResponse<T> ok(T data) { return new ApiResponse<>(HttpStatus.OK, data); } public static <T> ApiResponse<T> fail(HttpStatus status, T data) { return new ApiResponse<>(status, data); } }
정해민

@Mock VS @MockBean

  • @MockBean은 스프링 컨테이너를 올려서 테스트를 할 때 기존 빈을 목으로 대체 해준다.
www.baeldung.com
https://www.baeldung.com/java-spring-mockito-mock-mockbean

ReflectionTestUtils

테스트에서 사용할 데이터로 엔티티를 생성해야 하는 경우 id와 같이 private하고 setter 또는 생성자를 통해 설정할 수 없는 필드에 어떻게하면 원하는 값을 설정해 줄 수 있을지 찾아보다 알게 되었습니다.
  • 테스트에서 private 필드에 값을 설정하거나, private 메서드를 호출할 수 있습니다.
  • 클래스 이름에서 볼 수 있듯이 내부적으로 리플렉션을 사용합니다.
www.baeldung.com
https://www.baeldung.com/spring-reflection-test-utils
최지훈
JPA 테이블의 상속 관계 매핑에 대해 궁금한 점이 많았는데 이 블로그에서 도움을 얻었습니다!
Entity Inheritance in Hibernate - (2) Single-Table 상속 전략
Single-Table 상속 전략은 상속 관계에 있는 Entity를 모두 묶어서 하나의 Table로 만드는 방식이다. 이전에 사용한 예제를 Single-Table 상속전략을 사용했을 경우를 개념적으로 도식화 하면 과 같다. 최상위 Class인 Product Class가 모든 Child Class를 포함하는 상태로 Table이 만들어지며 다른 Entity Class와의 Relation도 이 Class에서 처리된다.
Entity Inheritance in Hibernate - (2) Single-Table 상속 전략
https://browndwarf.tistory.com/54
Entity Inheritance in Hibernate - (2) Single-Table 상속 전략
 
최현웅
Sql - 서브쿼리
Mysql - group by, having, max(count), inner query 예제 (가장 많이 조회된 글의 번호 구하기)
가장 많이 조회된 글 번호 구하기 쿼리 예제 이번 포스팅에는 가장 많이 조회된 글의 번호를 구하는 쿼리를 알아보도록 하겠습니다. 이런식으로 글 번호마다 언제 조회를 했는지를 저장하는 테이블입니다. 2.1 no별 조회수 구하기 (Group by) 우선 각 no 별 조회수를 구하기 위해 group by 를 이용하여 쿼리를 작성합니다.
Mysql - group by, having, max(count), inner query 예제 (가장 많이 조회된 글의 번호 구하기)
https://galid1.tistory.com/567
Mysql - group by, having, max(count), inner query 예제 (가장 많이 조회된 글의 번호 구하기)
DTO의 사용 범위에 대하여
DTO(Data Transfer Object)란 계층간 데이터 교환을 위해 사용하는 객체(Java Beans)입니다. 간략하게 DTO의 구체적인 용례 및 필요성을 MVC 패턴 을 통해 알아볼까요? 🚀 MVC 패턴은 어플리케이션을 개발할 때 그 구성 요소를 Model과 View 및 Controller 등 세 가지 역할로 구분하는 디자인 패턴입니다. 비즈니스 처리 로직(Model)과 UI 영역(View)은 서로의 존재를 인지하지 못하고, Controller가 중간에서 Model과 View의 연결을 담당합니다.
DTO의 사용 범위에 대하여
https://tecoble.techcourse.co.kr/post/2021-04-25-dto-layer-scope/
DTO의 사용 범위에 대하여