μ€νλ§ μ λ¬Έ - (3) Welcome Page λ§λ€κΈ° / View νκ²½μ€μ

main/resources/static μ idex.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>
<a href = " "> νκ·Έμ μμ±μ λ€λ₯Έ μΉμ¬μ΄νΈλ‘ λ§ν¬λ₯Ό νλ κΈ°λ₯μ
λλ€.
aλ <a> νκ·Έ μ
λλ€. μΈλΆ λ¬Έμλ λ΄λΆ λ¬Έμλ₯Ό λ§ν¬ν λ μ¬μ©νλ νκ·Έμ
λλ€.
hrefλ hypertext referenceμ μ½μλ‘ μ€μ λ‘ μ΄λν μΉνμ΄μ§μ μ£Όμλ₯Ό λ€μ μ λ μμ±μ
λλ€.

μλ²λ₯Ό κ»λ€κ° λ€μ ν€κ³
localhost:8080 μ μ

Welcome Page μμ± μλ£
νμνκ²μ μ°Ύλ λ₯λ ₯
https://spring.io/projects/spring-boot
Spring Boot
Commercial support Business support from Spring experts during the OSS timeline, plus extended support after OSS End-Of-Life. Publicly available releases for critical bugfixes and security issues when requested by customers.
spring.io
Learn - Reference Doc λ€μ΄κ°μ μ°Ύκ³ μΆμ ν€μλ κ²μ

index.html νμΌμ static μμ λ¨Όμ μ°Ύκ³ , μ°Ύμ§ λͺ»νλ©΄
index ν¬νλ¦Ώμ μ°Ύλλ€
λ°©κΈ νκ²μ
μ μ νμ΄μ§ : λ΄κ° μμ±ν μμ€μ½λλ₯Ό μΉ λΈλΌμ°μ λ‘ κ·Έλλ‘ λ겨주λ κ² / νλ‘κ·Έλλ°μ΄ μλ
thymeleaf ν
νλ¦Ώ μμ§
thymeleaf 곡μ μ¬μ΄νΈ: https://www.thymeleaf.org/
μ€νλ§ κ³΅μ νν 리μΌ: https://spring.io/guides/gs/serving-web-content/
μ€νλ§λΆνΈ λ©λ΄μΌ: https://docs.spring.io/spring-boot/docs/2.3.1.RELEASE/reference/html/spring-boot-features.html#boot-features-spring-mvc-template-engines
07-01 ν¨ν€μ§ (Package)
07-01 ν¨ν€μ§ (Package)
μ¬λ¬λΆμ μλ§λ ν΄λλ₯Ό μ΄μ©νμ¬ νμΌμ μ λ¦¬ν΄ λ³Έ κ²½νμ΄ μμκ²μ΄λ€. νμΌ μ¬λ¬κ°κ° ν ν΄λμ λ€μ£½λ°μ£½ μμ¬ μμ λ νμΌλ€μ μ±κ²©μ λ§κ² λΆλ₯ν λ€μ μ ν΄λμ μ μ₯νλ μμΌλ‘β¦
wikidocs.net
μ¬λ¬λΆμ μλ§λ ν΄λλ₯Ό μ΄μ©νμ¬ νμΌμ μ λ¦¬ν΄ λ³Έ κ²½νμ΄ μμκ²μ΄λ€. νμΌ μ¬λ¬κ°κ° ν ν΄λμ λ€μ£½λ°μ£½ μμ¬ μμ λ νμΌλ€μ μ±κ²©μ λ§κ² λΆλ₯ν λ€μ μ ν΄λμ μ μ₯νλ μμΌλ‘ λ§μ΄λ€.
μλ°μ ν¨ν€μ§λ μ΄μ μμ ν λμΌν κ°λ μ΄λΌ ν μ μλ€. ν¨ν€μ§λ λΉμ·ν μ±κ²©μ μλ° ν΄λμ€λ€μ λͺ¨μ λμ μλ°μ λλ ν 리μ΄λ€.
μλ₯Ό λ€μ΄ HousePark, HouseKim λ±μ ν΄λμ€λ€μ houseλΌλ ν¨ν€μ§λ‘ λΆλ₯νλ©΄ νΈλ¦¬ν κ²μ΄λ€
05-02 ν΄λμ€
05-02 ν΄λμ€
μ΄λ² μ₯μμλ ν΄λμ€μ λν΄μ μμΈν μμ보μ. μ¬κΈ°μλ ν΄λμ€μ λν κ°λ μ μΈ μ€λͺ μ ν기보λ€λ κ°μ₯ κ°λ¨ν ν΄λμ€λ₯Ό μμ±νλ κ²μμλΆν° μμνμ¬ μ‘°κΈμ© ν΄λμ€μ κ·λͺ¨λ₯Ό ν€β¦
wikidocs.net
κ·Έ κΈ°λ₯μ λ°λ‘ κ°μ²΄(object)λ₯Ό λ§λλ κΈ°λ₯μ΄λ€.
κ°μ²΄μ μΈμ€ν΄μ€
ν΄λμ€μ μν΄μ λ§λ€μ΄μ§ κ°μ²΄λ₯Ό μΈμ€ν΄μ€λΌκ³ λ νλ€. κ·Έλ λ€λ©΄ κ°μ²΄μ μΈμ€ν΄μ€μ μ°¨μ΄λ 무μμΌκΉ?
μ΄λ κ² μκ° ν΄ λ³΄μ. Animal cat = new Animal() μ΄λ κ² λ§λ€μ΄μ§ catμ κ°μ²΄μ΄λ€. κ·Έλ¦¬κ³ catμ΄λΌλ κ°μ²΄λ Animalμ μΈμ€ν΄μ€(instance) μ΄λ€. μΈμ€ν΄μ€λΌλ λ§μ νΉμ κ°μ²΄(cat)κ° μ΄λ€ ν΄λμ€(Animal)μ κ°μ²΄μΈμ§λ₯Ό κ΄κ³μμ£Όλ‘ μ€λͺ
ν λ μ¬μ©λλ€. μ¦, "catμ μΈμ€ν΄μ€" 보λ€λ "catμ κ°μ²΄"λΌλ ννμ΄ "catμ Animalμ κ°μ²΄" 보λ€λ "catμ Animalμ μΈμ€ν΄μ€" λΌλ ννμ΄ ν¨μ¬ μ μ΄μΈλ¦°λ€.
Controller λ 무μμΈκ°?
μΉ μ΄ν리μΌμ΄μ
μμ 첫λ²μ§Έ μ§μ
μ
1. μ¬μ©μμ μμ²μ΄ μ§μ
νλ μ§μ (entry point)

hello.hellospring.controller ν¨ν€μ§ μμ±
HelloContrller ν΄λμ€ μμ±
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"
}
}

templates
hello.html μμ±
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Hello</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p th:text="'μλ
νμΈμ. ' + ${data}" >μλ
νμΈμ. μλ</p>
</body>
</html>
<html xmlns:th="http://www.thymeleaf.org">
th : thymeleaf ν¬νλ¦Ώ λ¬Έλ² ,
<p th:text="'μλ
νμΈμ. ' + ${data}" >μλ
νμΈμ. μλ</p>
model.addAttribute("data","hello!!");
value( μ¬κΈ°μλ "hello!!" ) κ° ${data} μΉν


@GetMapping("hello")
public String hello(Model model){
model.addAttribute("data","hello!!");
return "hello";
http GET λ°©μ , μΉ μ΄ν리μΌμ΄μ
μμ URL μ /hello λΌκ³ λ€μ΄μ€λ©΄(λ§€μΉμ΄ λλ©΄) μ΄ λ©μλλ₯Ό νΈμΆνλ€
Model model
μ€νλ§μ΄ λͺ¨λΈμ λ§λ€μ΄ λ£μ΄μ€λ€
return "hello";
--> resources/templates μ μλ hello.html μκ°μ λ λλ§ν΄λΌ , μ΄ νλ©΄μ μ€νμμΌλΌ , λͺ¨λΈμ λκΈ°λ©΄μ

resources:templates/hello.html
μ¬κΈ°μλ hello κ° {ViewName}