HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
♥️
2기 최종 프로젝트 팀별 공간
/
💸
10원모아10조❗️
/
🏝️
Back End
/
📂
Convention
📂

Convention

Java ConventionTeam Convention테스트 메소드 이름예외처리DTO 네이밍Converter주석Database 패키지 구조(미정) ValidationDocumentationCommit ConventionPR, Issue Convention

Java Convention


  • Naver Convention
    • CheckStyle 사용해 빌드 할 때 검사
    • CheckStyle Reference
      Java lint 코드정적분석 checkstyle 사용하기
      팀 프로젝트를 하면서 비지니스 로직 이외에 code formatting 과 같이 다른 부분에서 리뷰를 남기거나 신경을 써야하는 것이 또 다른 낭비라고 생각했다. 모두가 좀 더 깔끔한 코드 형태를 보면서 비지니스 로직에 집중했으면 하는 마음에서 린트 설정을 알아보게 되었다. 실제로 근로에서는 kotlin을 사용하는데, ktlint를 사용하여 코드 컨벤션이 맞지 않으면 커밋 자체가 되지 않도록 설정되어 있다.
      Java lint 코드정적분석 checkstyle 사용하기
      https://nauni.tistory.com/m/275
      Java lint 코드정적분석 checkstyle 사용하기
      intelliJ, Checkstyle 과 formatter 셋업하기
      혼자만의 프로젝트든, 함께하는 프로젝트든, 기본적인 코드컨벤션이 있다면 코드의 가독성은 확 높아집니다. 그런데 이런 코드 컨벤션을 세워도, 매번 기억하거나 유의하기 어려울 때도 있죠. PR 에 코드 컨벤션에 대한 코멘트만 적힌다면, 마음이 상하기도 쉽습니다. 이런 부분은 코드의 정적분석으로 해결할 수 있는데요. sonarqube 같은 정적 분석기를 github에 붙일 수도 있겠지만, 일단 개개인의 ide에서 코드 컨벤션을 잡아주고 수정해줄 수 있는 방법이 필요합니다.
      intelliJ, Checkstyle 과 formatter 셋업하기
      https://juneyr.dev/checkstyle
      intelliJ, Checkstyle 과 formatter 셋업하기
      BE-02-MarBox/build.gradle at main · prgrms-be-devcourse/BE-02-MarBox
      This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters You can't perform that action at this time. You signed in with another tab or window.
      BE-02-MarBox/build.gradle at main · prgrms-be-devcourse/BE-02-MarBox
      https://github.com/prgrms-be-devcourse/BE-02-MarBox/blob/main/build.gradle
      BE-02-MarBox/build.gradle at main · prgrms-be-devcourse/BE-02-MarBox
 

Team Convention


테스트 메소드 이름

  • 한글로 명시해서 사용하자.
    • 테스트 클래스에 DisplayName으로 한글명 처리하기.
@DisplayName("지출 api 통합/인수 테스트") class ExpenditureControllerTest{ }
 

예외처리

  • 에러 메시지 내용
    • 프론트랑 협의해서 정하자
  • 핸들러 단위
    • 1개의 GlobalExceptionHandler 로 처리
  • 커스텀 Exception
    • 최대한 존재 하는 예외를 사용하고, 없을 때 커스텀을 추가해서 사용하자
  • 예외처리 핸들러 위치
    • 클래스 위치 : ../exception/handler
 

DTO 네이밍

  • [Create | Update | Find | Delete] + [도메인 이름] + [Request or Response]
    • ex) CreateUserRequest, UpdateUserResponse
 

Converter

  • Dto안에서 책임진다.
    • Entity에는 포함시키면 안됨.
ex) Request
class CreateUserRequset{ public User toEntity(){ return user; } }
ex) Response
class CreateUserResponse{ public static CreateUserResponse of(User user){ return new CreateUserResponse(user.get...); } }
 

주석

주석이 필요한 경우 추가하기
@Service @Transational(readOnly=true) public class UserService { ... /** * 로그인하는 메서드 * @param email (이메일) * @param password (비밀번호) * @return ResponseLoginUser */ public ResponseLoginUser login(String email, String password) { ... } }
 

Database

  • FK 이름 설정 - fk_현재테이블_참조하는테이블
    • why?
      notion image
      • 실제 fk에서 문제가 생겼을때 문제 생긴 fk의 이름을 지정해주지 않아서 찾는데 어려움을 겪는 문제가 발생하였습니다.
      @ManyToOne(fetch = LAZY) @JoinColumn( foreignKey = @ForeignKey(name = "fk_expenditure_user"), name = "user_id") private User user; @OneToOne(fetch = LAZY) @JoinColumn( foreignKey = @ForeignKey(name = "fk_expenditure_user_category"), name = "user_category_id") private UserCategory userCategory;
      ref
      kotlin에서 jpa 사용시 ForeignKey로 이름을 부여하고 싶은 경우
      kotlin에서 jpa 사용시 ForeignKey로 이름을 부여하고 싶은 경우
      https://www.slipp.net/questions/599
      kotlin에서 jpa 사용시 ForeignKey로 이름을 부여하고 싶은 경우
 

패키지 구조(미정)

  • 개발 좀 더 진행하면서 tree로 채워 넣기
    • 참조
      참고 : 토스 | SLASH 22 — 지속 성장 가능한 코드를 만들어가는 방법
      내용 요약
 

Validation

  • Spring-boot-Validation 사용
  • Entity에 대한 Validation은 구아바 사용
    • why? → Entity 규칙을 생성자에 강제하여 가독성을 높인다.
    •  

Documentation

  • RestDocs로 작성하고, Swagger와 연동하여 배포한다.
    • RestDocs작성 시 2개의 import를 사용한다. (주석처리된 import 사용하면 안된다.)
      • 참조
      // import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.*; import static com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper.*; // import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*;
 

Commit Convention


  • AngularJS
    • Intellij git commit template 적용
  • 커밋 메시지
    • 한글 위주로 작성, 필수 영어 표현만 기재

PR, Issue Convention


  • PR 네이밍
    • [#이슈 번호] 이슈 이름
  • PR 단위
    • 이슈 단위
  • Issue 제목 규칙
    • 이슈 별 레이블 추가 (feature, bug, refactor)
  • PR, Issue 템플릿 - 링크
    • Ref
      • https://medium.com/prnd/헤이딜러-개발팀-모두가-행복한-개발-pr관리-방법-7가지-1d4cd5d091f0
      • https://soft.plusblog.co.kr/66
  • Projects With Issue 처리 방식 정의
    • 이슈 등록 → Projects에서 프로젝트 선택
    • PR 요청
    • PR Merge하기 전에 Development에서 해당 이슈 선택