resources - static - index.html 생성

 

index.html
<!DOCTYPE HTML>
<html>
<head>
    <title>Hello</title>
    <meta http-equiv="content-type" content="text/html;" charset=UTF-8" />
</head>
<body>
Hello
<a href="/hello">hello</a>
</body>
</html>

 

 

controller - hello 찍기
1. controller 패키지 만들고 안에 HelloController 생성
2. resources - templates 폴더안에 hello.html 생성

 

HelloController.java
package hello.hellospring.controller;

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

@Controller
public class HelloController {
    
    @GetMapping("hello")
    public String hello(Model model){
        model.addAttribute("data", "hello!!");
        return "hello";
    }
}

 

hello.html
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Hello</title>
</head>
<body>
<p th:text="'안녕하세요. ' + ${data}">안녕하세요. 손님</p>
</body>
</html>

<html xmlns:th="http://www.thymeleaf.org">

-> thymeleaf 탬플릿 엔진을 사용하기 위해서 선언함

 

복사했습니다!