스프링 입문 - 5. 회원 관리 예제 - 웹 MVC 개발(1)

WooHyeong·2022년 8월 16일

Spring

목록 보기
7/27

회원 웹기능 - 홈 화면 추가

홈 컨트롤러 추가
package hello.hellospring.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class HomeController {

    @GetMapping("/")
    public String home(){
        return "home";
    }
}
회원 관리용 홈
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<body>
<div class="container">
    <div>
        <h1>Hello Spring</h1>
        <p>회원 기능</p>
        <p>
            <a href="/members/new">회원 가입</a>
            <a href="/members">회원 목록</a>
        </p>
    </div>
</div> <!-- /container -->
</body>
</html>

이전에 static에 index.html을 작성했었다. Welcome 페이지라고, 아무것도 없으면 index.html을 시작하도로 하였다. 정적 컨텐츠 부분에서 설명을 했었는데, 요청이 오면 스프링 컨테이너에서 관련 컨트롤러가 있는지 없으면 static 파일을 찾도록 되어있다.

컨트롤러가 정적 파일보다 우선순위가 높다.

profile
화이링~!

0개의 댓글