IOC: 개발자가 아니라 컨테이너에 의해서 Instance들을 생성되고 관리되는 방식.시나리오
관계
기능
조회
사용자 목록 조회
사용자 상세 조회
사용자 포스트 목록 조회
사용자 포스트 상세 조회
생성
삭제


Enable annotation processing 체크

Build project autiomaically 체크

application.properties 삭제 후 application.yaml 생성
application.yaml
server:
port: 8088
HelloWorldController 생성
/hello-world (URI는 사용자에 의해 호출되는 end-point)@RestController
public class HelloWorldController {
@GetMapping("/hello-world")
public String helloworld() {
return "Hello World";
}
}
http://localhost:8088/hello-world 접속 시


HelloWorldBean 빈을 반환하는 helloWorldBean 메소드 생성
자바빈 형태로 값을 반환할 경우 json 형식으로 반환이 됨
HelloWorldController
// HelloworldBean 형태의 자바 빈을 반환하는 메소드
@GetMapping("/hello-world-bean")
public HelloWorldBean helloWorldBean() {
return new HelloWorldBean("Hello World");
}
HelloWorldBean 생성
@Data
@AllArgsConstructor
@NoArgsConstructor
public class HelloWorldBean {
private String message;
}

사용자 정보가 DispatcherServlet에 전달 -> DispatcherServlet이 이 정보를 Handler Mapping / Controller에 전달 -> Controller가 처리된 결과값을 Model 형태로 DispatcherServlet에 전달 -> ViewResolver가 사용자에게 보여주고자 하는 포맷으로 페이지 생성 -> 페이지 값에 모델을 포함시켜서 전달
View를 갖지 않는 REST Data를 반환하는 서비스의 경우, View 형태의 페이지를 생성할 필요없이 사용자의 요청을 Json 포맷으로 전달하면 됨
http://localhost:8080/bookshttp://localhost:8080/books/1, URL : http://localhost:8080/books/123Path Variable : 동일한 패턴의 가변데이터를 가진 URI를 만들어 이러한 가변 데이터를 클라이언트가 사용할 때, 이 변수를 지칭함.HelloWorldController
@GetMapping("/hello-world-bean/path-variable/{name}")
public HelloWorldBean helloWorldBean2(@PathVariable String name) {
return new HelloWorldBean(String.format("Hello World, %s", name));
}
http://localhost:8088/hello-world-bean/path-variable/aaa 접속
