์Šคํ”„๋ง ์ž…๋ฌธ - (3) Welcome Page ๋งŒ๋“ค๊ธฐ / View ํ™˜๊ฒฝ์„ค์ •

2023. 1. 9. 13:32ยทSpring/Spring ์ž…๋ฌธ


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)

https://wikidocs.net/231

07-01 ํŒจํ‚ค์ง€ (Package)

์—ฌ๋Ÿฌ๋ถ„์€ ์•„๋งˆ๋„ ํด๋”๋ฅผ ์ด์šฉํ•˜์—ฌ ํŒŒ์ผ์„ ์ •๋ฆฌํ•ด ๋ณธ ๊ฒฝํ—˜์ด ์žˆ์„๊ฒƒ์ด๋‹ค. ํŒŒ์ผ ์—ฌ๋Ÿฌ๊ฐœ๊ฐ€ ํ•œ ํด๋”์— ๋’ค์ฃฝ๋ฐ•์ฃฝ ์„ž์—ฌ ์žˆ์„ ๋•Œ ํŒŒ์ผ๋“ค์„ ์„ฑ๊ฒฉ์— ๋งž๊ฒŒ ๋ถ„๋ฅ˜ํ•œ ๋‹ค์Œ ์ƒˆ ํด๋”์— ์ €์žฅํ•˜๋Š” ์‹์œผ๋กœโ€ฆ

wikidocs.net

์—ฌ๋Ÿฌ๋ถ„์€ ์•„๋งˆ๋„ ํด๋”๋ฅผ ์ด์šฉํ•˜์—ฌ ํŒŒ์ผ์„ ์ •๋ฆฌํ•ด ๋ณธ ๊ฒฝํ—˜์ด ์žˆ์„๊ฒƒ์ด๋‹ค. ํŒŒ์ผ ์—ฌ๋Ÿฌ๊ฐœ๊ฐ€ ํ•œ ํด๋”์— ๋’ค์ฃฝ๋ฐ•์ฃฝ ์„ž์—ฌ ์žˆ์„ ๋•Œ ํŒŒ์ผ๋“ค์„ ์„ฑ๊ฒฉ์— ๋งž๊ฒŒ ๋ถ„๋ฅ˜ํ•œ ๋‹ค์Œ ์ƒˆ ํด๋”์— ์ €์žฅํ•˜๋Š” ์‹์œผ๋กœ ๋ง์ด๋‹ค.

์ž๋ฐ”์˜ ํŒจํ‚ค์ง€๋„ ์ด์™€ ์™„์ „ํžˆ ๋™์ผํ•œ ๊ฐœ๋…์ด๋ผ ํ• ์ˆ˜ ์žˆ๋‹ค. ํŒจํ‚ค์ง€๋Š” ๋น„์Šทํ•œ ์„ฑ๊ฒฉ์˜ ์ž๋ฐ” ํด๋ž˜์Šค๋“ค์„ ๋ชจ์•„ ๋†“์€ ์ž๋ฐ”์˜ ๋””๋ ‰ํ† ๋ฆฌ์ด๋‹ค.

 ์˜ˆ๋ฅผ ๋“ค์–ด HousePark, HouseKim ๋“ฑ์˜ ํด๋ž˜์Šค๋“ค์€ house๋ผ๋Š” ํŒจํ‚ค์ง€๋กœ ๋ถ„๋ฅ˜ํ•˜๋ฉด ํŽธ๋ฆฌํ•  ๊ฒƒ์ด๋‹ค


05-02 ํด๋ž˜์Šค

https://wikidocs.net/214

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
'Spring/Spring ์ž…๋ฌธ' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€
  • ์Šคํ”„๋ง ์ž…๋ฌธ - (5) ์ •์  ์ปจํ…์ธ 
  • ์Šคํ”„๋ง ์ž…๋ฌธ - (4) ๋นŒ๋“œํ•˜๊ณ  ์‹คํ–‰ํ•˜๊ธฐ
  • ์Šคํ”„๋ง ์ž…๋ฌธ - (2) ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ดํŽด๋ณด๊ธฐ
  • ์Šคํ”„๋ง ์ž…๋ฌธ - (1) ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ
hello_u
hello_u
  • hello_u
    ๐Ÿ˜œ
    hello_u
  • ์ „์ฒด
    ์˜ค๋Š˜
    ์–ด์ œ
    • ๐Ÿ˜œ (345)
      • Hardware (2)
        • BMC (2)
      • Spring (109)
        • Spring ์ž…๋ฌธ (20)
        • Spring ๊ธฐ๋ณธ (27)
        • Spring MVC (18)
        • Spring DB (22)
        • Spring JPA ๊ธฐ๋ณธ (16)
        • Spring JPA ํ™œ์šฉ (6)
      • Develop (27)
        • DB (8)
        • JAVA (4)
        • Web (2)
        • Python (7)
        • OSS (2)
        • Git (2)
        • API (2)
      • Algorithm (155)
        • CodeUp ๊ธฐ์ดˆ (44)
        • ํŒŒ์ด์ฌ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ (64)
        • ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค (4)
        • SWEA (30)
        • Softeer (10)
        • BOJ (2)
      • CS (9)
        • ์ปดํ“จํ„ฐ์ผ๋ฐ˜ (3)
        • ์šด์˜์ฒด์ œ (3)
        • ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค (0)
        • ์ •๋ณดํ†ต์‹  (1)
        • ์ž๋ฃŒ๊ตฌ์กฐ (1)
        • ์†Œํ”„ํŠธ์›จ์–ด ๊ณตํ•™ (1)
        • ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด (0)
        • ์ตœ์‹  ๋””์ง€ํ„ธ, ์ผ๋ฐ˜์ƒ์‹ (0)
      • ์ž๊ฒฉ์ฆ (41)
        • ์ •๋ณด๋ณด์•ˆ๊ธฐ์‚ฌ (9)
        • ์ •๋ณด์ฒ˜๋ฆฌ๊ธฐ์‚ฌ (22)
        • ๋ฆฌ๋ˆ…์Šค๋งˆ์Šคํ„ฐ 1๊ธ‰ (3)
        • SQLD (7)
  • hELLOยท Designed By์ •์ƒ์šฐ.v4.10.3
hello_u
์Šคํ”„๋ง ์ž…๋ฌธ - (3) Welcome Page ๋งŒ๋“ค๊ธฐ / View ํ™˜๊ฒฝ์„ค์ •
์ƒ๋‹จ์œผ๋กœ

ํ‹ฐ์Šคํ† ๋ฆฌํˆด๋ฐ”