Hello hello "> Title Hello hello "> Title Hello hello ">

static 우클릭 → New → HTML 파일 생성

static 우클릭 → New → HTML 파일 생성

index.html 파일 생성

index.html 파일 생성

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
</head>
<body>
    Hello
    <a href="/hello">hello</a>
</body>
</html>

잘 떴음!

잘 떴음!

링크타고 들어가면 아무것도 없으니 당연히 에러남

링크타고 들어가면 아무것도 없으니 당연히 에러남

<aside> 💡 타임리프 공식 사이트 스프링 공식 튜토리얼 스프링부트 공식 문서

</aside>

템플릿 툴들 종류

템플릿 툴들 종류

hello.hellospring 우클릭 → New → Package 생성

hello.hellospring 우클릭 → New → Package 생성

패키지 이름: controller

패키지 이름: controller

controller → New → Java Class

controller → New → Java Class

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) {
				//dataname: data, value: "hello!!"
        model.addAttribute("data", "hello!!");
				// return이 hello인 것은 templates의 hello.html 파일을 찾으라는 소리.
        return "hello";
    }
}
<!DOCTYPE HTML>
<!-- thymleaf 문법을 쓰기 위해 임포트 -->
<html xmlns:th="<http://www.thymeleaf.org>">
  <head>
    <title>Hello</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  </head>
  <body>
    <!-- ${data} 부분은 HelloController의 data, value(hello!!)로 치환됨 -->
    <p th:text="'안녕하세요. ' + ${data}" >안녕하세요. 손님</p>
  </body>
</html>

Untitled

페이지 우클릭 → 페이지 소스 코드 보기

페이지 우클릭 → 페이지 소스 코드 보기

Untitled

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", **"spring!!"**);
        return "hello";
    }
}

Untitled