개발공부/[spring]김영한_스프링입문

Thymleaf가 뭔데?

개발자 덕구🐾 2022. 8. 9. 13:52
728x90

타임리프 공식 사이트 : 

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

 

 

 

 

thymleaf는 템플릿 엔진 중 하나이다. 

 

 

 

 

 

템플릿 엔진은 서버의 데이터와 정적자원(html, css)를 조합하여 결과물을 만들어주는 도구이다. 

Natural Template를 기반으로 하는데 이는 기존 HTML코드와 구조를 변경하지 않고 덧붙이는 방식이다. 

 

spring boot에서는 타임리프 사용을 권장하고 있다. 

 

 

 

 

 

타임리프로 작성된 HTML 템플릿은 실제 작동하는 템플릿을 잘 작동하게 만들면서 여전히 HTML처럼 보이고 작동한다. 

 

 

 

 

 

 

 

@Controller
public class HelloController {

    @GetMapping("hello")
    public String hello(Model model){
        model.addAttribute("data","hello!!");

        // resources -> templates -> hello.html을 찾아 open한다.
        return "hello";
    }
}

이렇게 코드를 만들면 localhost:8080/hello를 하면 타임리프가 

resources/templates/ + {ViewName} + .html 으로 매핑한다.  ( 여기서는 ViewName이 html이다.) 

 

 

 

 

 

 

반응형