100일 챌린지/빅데이터기반 인공지능 융합 서비스 개발자

Day 72 - thymeleaf template engine을를 이용한 view 페이지 만들기

ksyke 2024. 11. 11. 15:47

목차

    https://www.thymeleaf.org/

    [Thymeleaf

    Integrations galore Eclipse, IntelliJ IDEA, Spring, Play, even the up-and-coming Model-View-Controller API for Java EE 8. Write Thymeleaf in your favourite tools, using your favourite web-development framework. Check out our Ecosystem to see more integrati

    www.thymeleaf.org](https://www.thymeleaf.org/)

    pom.xml

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-thymeleaf</artifactId>
            </dependency>

    ProjectApplication

    @Controller
    @SpringBootApplication
    public class Sts07Application {
    
    	public static void main(String[] args) {
    		SpringApplication.run(Sts07Application.class, args);
    	}
    
    	@GetMapping("/test1")
    	public String test1(Model model) {
    		model.addAttribute("msg", "Hello World");
    		return "test1";
    	}
    }

    resources>template>html

    <!DOCCTYPE html>
    <html>
    <head>
    	<meta charset="UTF-8">
    	<title>thymeleaf</title>
    </head>
    <body>
    	<h1 th:text="${msg}">thymeleaf로 view 출력</h1>
    </body>
    </html>


    resources>static>html

    <!DOCCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8">
        <title>thymeleaf</title>
    </head>
    <body>
        <h1>static page</h1>
    </body>
    </html>