File tree Expand file tree Collapse file tree
java/hello/hellospring/controller Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package hello .hellospring .controller ;
2+
3+ import org .springframework .stereotype .Controller ;
4+ import org .springframework .web .bind .annotation .GetMapping ;
5+
6+ @ Controller
7+ public class HomeController {
8+
9+ /*
10+ 슬래시(/)는 도메인 첫번째인 localhost:8080으로 들어오면 @GetMapping("/")로 연결된 public String home()이 호출됩니다.
11+ 그리고 해당 함수안의 내용을 보고 src\main\resources\templates에 있는 home.html이 호출됩니다
12+ src\main\resources\static 의 index.html이 실행되지 않는 이유? -> 우선순위가 있습니다. 클라이언트 요청이 왔을 때
13+ 스프링 컨테이너안에 있는 관련 컨트롤러를 먼저 찾고 없으면 static 파일을 찾아서 띄워줍니다.
14+ localhost:8080 요청이 있으면 먼저 컨트롤러에서 찾아서 @GetMapping("/")를 보고 해당 컨트롤러의 함수가 호출되고 home.html을 보여줍니다.
15+
16+ */
17+ @ GetMapping ("/" )
18+ public String home (){
19+ return "home" ;
20+ }
21+
22+ }
Original file line number Diff line number Diff line change 1+ <!DOCTYPE HTML>
2+ < html xmlns:th ="http://www.thymeleaf.org ">
3+ < body >
4+ < div class ="container ">
5+ < div >
6+ < h1 > Hello Spring</ h1 >
7+ < p > 회원 기능</ p >
8+ < p >
9+ < a href ="/members/new "> 회원 가입</ a >
10+ < a href ="/members "> 회원 목록</ a >
11+ </ p >
12+ </ div >
13+ </ div > <!-- /container -->
14+ </ body >
15+ </ html >
You can’t perform that action at this time.
0 commit comments