Skip to content

Commit d513465

Browse files
회원 웹 기능 개발 @GetMapping("/") 스프링 컨테이너 안에 있는 컨트롤러 -> 없으면 static
1 parent 06b4b96 commit d513465

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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>

0 commit comments

Comments
 (0)