New Project


Demo


코드
package com.example.demo.controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import java.util.Random; @RestController // -> 컴포넌트 스캔임 public class HelloController { public HelloController() { System.out.println("HelloController 컴포넌트 스캔됨"); } @GetMapping("/home") public void home() { System.out.println("home 호출됨"); } @GetMapping("/hello") public String hello(){ String name = "홍길동"; return "<h1>hello "+name+"</h1>"; } @GetMapping("/random") public String random(){ Random r = new Random(); int num = r.nextInt(5)+1; return "<h1>random "+num+"</h1>"; } }
@RestController → component scan
org.example.bank이하의 클래스들을 스캔하여 @RestController가 붙은 모든 클래스들을 new한다.
new한 클래스들을 ioc 컨테이너에 보관한다.(절때 가비지 컬렉션이 안됨.)
ioc : inversion of control(제어 역전) → 스프링에게 new의 제어권을 위임하는 것
스프링을 공부한다는 것은 어노테이션 공부한다는 것.
개발자들은 어노테이션만 해주면 스프링이 알아서 해줌
정적 페이지 : 동일한 페이지가 return

동적 페이지 : 매번 다른 페이지가 return

동적페이지를 쓰는 이유는 정적페이지를 사용하면 다른 페이지를 계속 만들어야함
→ 파일이 늘어남
Share article