대충이라도 하자

Spring Boot Tutorial | Full Course [2021] (4) 본문

꼬꼬마 개발자 노트/Spring

Spring Boot Tutorial | Full Course [2021] (4)

Sueeeeee
반응형

이번에는 Api Layer 만들기

1. student 패키지 안에 studentController 만듭니다

( 메인 클래스에 있던 @restController 라던지 전부 다 지워주세요 -> 처음 상태로!)

***@RequestMapping으로 경로 지정해주기

2. 로컬호스트의 경로 대로 들어가면 아래와 같이 출력

다음으로 Business Layer 만들기

Api Layer에서 Business Layer로 말 걸고 Business Layer가 Data Access Layer한테 말 겁니다.ㅋㅋㅋ

먼저, Student 패키지에 StudentService 클래스 만드세요

3. studentController에 있던 메서드를 studentService로 옮기기

4. controller를 아래와 같이 수정

여기서 끝난 게 아님!!!!

5. Service에 @Service 어노테이션 붙여주기

@Component도 가능하나 @Service가 더 semantic함

6. Controller에도 @Autowired 어노테이션을 붙여서 인젝션 해줘야 비로소 api layer와 business layer가 나뉘어 진 것

반응형
Comments