MapleStory Finger Point

๐ŸŸค JAVA/๐ŸŸค Spring

[Spring boot] Thymeleaf + Model

HYEJU01 2024. 9. 5. 23:45

 

 

 

 

 

 

 

 

๋ ˆ์ด์•„์›ƒ ํ…œํ”Œ๋ฆฟ ์ ์šฉ: layout03 ํ…œํ”Œ๋ฆฟ์— container ๋ถ€๋ถ„์„ ์ „๋‹ฌํ•˜์—ฌ ํ•ด๋‹น ํ…œํ”Œ๋ฆฟ์˜ ํŠน์ • ๋ถ€๋ถ„๋งŒ ๊ต์ฒดํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค. ์ด์ฒ˜๋Ÿผ ์—ฌ๋Ÿฌ ํŽ˜์ด์ง€์—์„œ ๊ณตํ†ต๋œ ๋ ˆ์ด์•„์›ƒ์„ ์œ ์ง€ํ•˜๋ฉด์„œ, ํŠน์ • ๋ถ€๋ถ„๋งŒ ๋™์ ์œผ๋กœ ๊ต์ฒดํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	
	<h3>์ด ํ™”๋ฉด์— ์ง„์ž…ํ•  ๋•Œ TestVO๋ฅผ Model์— ๋‹ด์•„ ํ™”๋ฉด์ฒ˜๋ฆฌ๋ฅผ ํ•ฉ๋‹ˆ๋‹ค.</h3>
	<p>
		1. ํšŒ์›์ •๋ณดํ™•์ธ ๋งํฌ์—๋Š” quiz_result01?ํ‚ค=๊ฐ’ ํ˜•ํƒœ๋กœ ๋ฒˆํ˜ธ๋ฅผ ๋„˜๊ธฐ๊ณ  ์ถœ๋ ฅํ•ด ์ฃผ์„ธ์š”

		2. ์•„๋ž˜ class="container" ๋ถ€๋ถ„๋งŒ layout03 ํ…œํ”Œ๋ฆฟ์— ์ „๋‹ฌ ๋  ์ˆ˜ ์žˆ๋„๋ก ์ฒ˜๋ฆฌํ•˜์„ธ์š”
	</p>




	<th:block th:replace="~{/include/layout03 :: ํ•จ์ˆ˜( ~{ :: .container } ) }">

	<div class="container">
		ํšŒ์›๋ฒˆํ˜ธ: [[${vo.num}]]
		์ด๋ฆ„: [[${vo.name}]]
		๋‚˜์ด: [[${vo.age}]]
		<br>
		<a th:href="@{/view/quiz01_result(num=${vo.num}) }">ํšŒ์›์ •๋ณดํ™•์ธ</a>
	</div>

	</th:block>
	
	
	
</body>
</html>

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

    <h3>๊ฒฐ๊ณผํ™”๋ฉด</h3>
    ๋„˜์–ด์˜จ ๊ฐ’: [[${num}]]
</body>
</html>

 

 

    @GetMapping("/quiz01")
    public String qui01(Model model) {

        TestVO vo = TestVO.builder()
                .num(1)
                .name("ํ™๊ธธ๋™")
                .addr("์„œ์šธ์‹œ")
                .age(20)
                .build();

        model.addAttribute("vo", vo);

        return "view/quiz01";
    }

    @GetMapping("/quiz01_result")
    public String quiz01_result(@ModelAttribute("num") String num) { //๋‹ค์Œ ํ™”๋ฉด์—์„œ num์ด๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ ์“ธ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์คŒ
        return "view/quiz01_result";
    }