Development

[ThymeLeaf] Spring Boot에 타임리프 추가하기

Hits: 330

gradle 기준 – build.gradle에 하단 추가

  • implementation ‘org.springframework.boot:spring-boot-starter-thymeleaf’

application.properties에 하단 추가

  • spring.thymeleaf.prefix=classpath:/templates/
  • spring.thymeleaf.suffix=.html
  • spring.thymeleaf.mode=HTML
  • spring.thymeleaf.encoding=UTF-8
  • spring.thymeleaf.cache=false

기본 html 추가

/resources/templates/index.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Title</title>
</head>
<body>
    <h1>테스트</h1>
</body>
</html>

Controller에 하단 내용 추가

@GetMapping("/index")
    public String index(Model model) {
        
        return "index";  // src/main/resources/templates/index.html을 가리킴
    }

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다