본문 바로가기

분류 전체보기474

Exception 처리 Web Application의 입장에서 바라보았을때, 에러가 났을 때 내려줄 수 있는 방법은 많지 않다. 1. 에러 페이지 2. 4XX Error or 5XX Error 3. Client가 200 외에 처리를 하지 못 할 때는 200을 내려주고 별도의 에러 Message 전달 @ControllerAdvice Global 예외 처리 및 특정 package / Controller 예외 처리 @ExceptionHandler 특정 Controller의 예외처리 전체 시스템에서 예외 처리를 하는 방법 dto 작성 package com.example.exception.dto; import javax.validation.constraints.Min; import javax.validation.constraints.N.. 2021. 6. 19.
Custom Validation 1. AssertTrue / False 와 같은 method 지정을 통해서 Custom Logic 적용 가능 // 입력받은 날짜가 올바른 형식인지 확인 함수 앞에 is라는 명칭을 붙여줘야 동작한다. @AssertTrue(message = "yyyyMM의 형식에 맞지 않습니다.") public boolean isreqYearMonthValidation(){ System.out.println("assert true call"); // LocalDate은 기본적으로 yyyyMMdd 형식이므로 받은 데이터에 강제적으로 DD값을 임의로 붙여준다. String bDate = getReqYearMonth() + "01"; try{ LocalDate localDate = LocalDate.parse(bDate, Dat.. 2021. 6. 19.
Validation Validation이란 프로그래밍에 있어서 가장 필요한 부분이다. 특히 java에서는 null값에 대해서 접근하려고 할 때 null pointer exception이 발생 함으로, 이러한 부분을 방지 하기 위해서 미리 검증을 하는 과정을 Validation이라고 한다. 단순 코드 예제 public void run(String account, String pw, int age){ if (account == null || pw == null){ return; } if (age == 0){ return; } // 정상 처리할 logic } 검증해야 할 값이 많은 경우 코드의 길이가 길어 진다. 구현에 따라서 달라 질 수 있지만 Service Logic과의 분리가 필요 하다. 흩어져 있는 경우 어디에서 검증을 .. 2021. 6. 19.
type alias 와 interface type alias : 어떤 타입을 부르는 이름 interface : 어떤 새로운 타입을 만들어 내는 것 함수를 선언할 때 차이 // function // type alias type EatType = (food: string) => void; // interface interface IEat { (food: string): void; } 배열을 선언할 때 차이 // array // type alias type PersonList = string[]; // interface interface IPersonList { [index: number]: string; } interscection을 선언 할 때 차이 interscection: 여러 타입을 합쳐서 사용하는 타입 interface ErrorHandl.. 2021. 6. 19.
인터페이스에 readonly 설정하는 방법 인터페이스 변수에 readonly를 설정하면 처음 선언했던 변수를 수정할 수 없다. // 인터페이스 선언 interface Person8 { name: string; age?: number; readonly gender: string; } const p81: Person8 = { name: 'Mark', gender: 'male' } // readonly 이기 때문에 변경 불가 // p81.gender = "female"; console.log(p81); console.log(p81.name); console.log(p81.gender); 2021. 6. 19.
함수선언할때 인터페이스 사용하는 방법 함수선언할때 인터페이스 사용하는 방법 interface HelloPerson { (name: string, age?: number): void; } // 함수 생성 const helloPerson: HelloPerson = function(name: string, age?: number){ console.log(`안녕하세요! ${name} 입니다.`) } // 함수 사용 helloPerson("mark", 22); 2021. 6. 19.