
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}
'Spring > Spring ์ ๋ฌธ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์คํ๋ง ์ ๋ฌธ - (5) ์ ์ ์ปจํ ์ธ (0) | 2023.01.12 |
---|---|
์คํ๋ง ์ ๋ฌธ - (4) ๋น๋ํ๊ณ ์คํํ๊ธฐ (0) | 2023.01.10 |
์คํ๋ง ์ ๋ฌธ - (2) ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ดํด๋ณด๊ธฐ (0) | 2023.01.09 |
์คํ๋ง ์ ๋ฌธ - (1) ํ๋ก์ ํธ ์์ฑ (0) | 2023.01.08 |
์คํ๋ง ์ ๋ฌธ - (0) ์คํ๋ง์ ์ ๊ณต๋ถํด์ผ ํ๋๊ฐ (0) | 2023.01.07 |