1. ResponseEntity
ResponseEntity는 @controller/@restcontroller 상관없이 무조건 데이터(json) 응답
ResponseEntity는 상태코드를 리턴할 수 있다.
인수는 body, 상태코드
body와 상태코드
상태코드는 숫자로 작성X HttpStatus.OK 처럼 사용
// Resp 최종 형태
package shop.mtcoding.blog._core.util;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
// 1. @ResponseEntity는 @Controller, @RestController 상관없이 무조건 데이터(json)를 응답
// 2. @ResponseEntity는 상태코드를 리턴할 수 있다.
// 3. 인수(body, 상태코드)
@AllArgsConstructor
@Data
public class Resp<T> {
private Integer status;
private String msg;
private T body;
// ResponseEntity 형태로 바로 리턴 (성공)
public static <B> ResponseEntity<Resp<B>> ok(B body) {
Resp<B> resp = new Resp<>(200, "성공", body);
return new ResponseEntity<>(resp, HttpStatus.OK);
}
// ResponseEntity 형태로 바로 리턴 (실패)
public static ResponseEntity<Resp<?>> fail(HttpStatus status, String msg) {
Resp<?> resp = new Resp<>(status.value(), msg, null);
return new ResponseEntity<>(resp, status);
}
}- 제네릭, 와일드카드, 제네릭 static 문법 공부 (2시간이면 합니다..예.._ →java 프로젝트 열어서)
1.전체를 restcontroller로 변경
2.로그아웃의 개념이 없다 → 코드 삭제! (⇒ AccessToken만으로는 로그아웃을 만들 수 없다.

내가 직접 json을 serializable해서 한거라 제대로X?(00:18:00) → 원래 방식은 integer status임
f-ds-interceptor-c
controller가 ResponseEntity를 응답. 결국은 ResponseEntityㅇ르 응답하는게 아니라 DS에서 ResponseEntity에 들어있는 body와 상태코드를 꺼내고 ResponseEntity를 버린다. 상태코드도 번호만 꺼내서 버림. body는 json으로 변환하고. ResponseEntity를 응답하는게 아님 근데 filter에서 ResponseEntity를 응답하면 ResponseEntity 안의 전부를 리턴하게 됨.

2. Enum
문법은 스스로 공부해야됨

데이터의 범주
오브젝트의 범주 = 비지니스의 범주
?
@Test
public void create_test(){
// Apply를 만드는 입장에서 보면
Apply apply1 = new Apply(1,"홍길동",3, ApplyStatus.PASS);
// apply.setId(1);
// apply.setName("홍길동");
// apply.setComId(3);
// apply.setStatus("오케이"); // 리터럴 : 문자열을 그대로 넣는 것 => 나중에는 리터럴을 전부 없앰. -> 클래스로 값을 집어넣고 씀 실수할수도있고 보안에도 안좋음
Apply apply2 = new Apply(2,"임꺽정",3,"합격");
}목표 1&2
- 이런일 없도록

- 뭘 넣을지 알도록 (→ 주석처리하면 되긴 하지만








Enum이 있기 전에 어떻게 썼는지?
Share article