Thymeleaf템플릿 사용
jsp와 문법이 크게 다르지 않다.
jsp뷰가 있으면 덮어씌워져 실행이 안된다.
build.gradle과 application.properties에서 jsp, jstl 관련 구문 주석처리.
이전에 생성한 webapp-WEB-INF-views폴더 및 파일 전부 삭제.
maven repository에서
Spring Boot Starter Thymeleaf로 가져옴
gradle에
dependencies {
...
//Thymeleaf를 사용
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
}
넣고
gradle refresh
별다른 설정 없이
src/main/resources의
templates아래에
home.html로 파일 생성
home.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
타임리프 뷰
</body>
</html>
컨트롤러를 만들어놔서 자동적으로 들어간다.
package com.simple.basic.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class HomeController {
@GetMapping("/")
public String home() {
return "home";
}
}
templates아래에 html을 만들면, 컨트롤러를 탄다.
'Spring Boot' 카테고리의 다른 글
230210 Spring Boot Builder패턴(디자인패턴) (0) | 2023.02.10 |
---|---|
230210 Spring Boot 개별적인 bean 생성, 테스트코드 (0) | 2023.02.10 |
230210 Spring Boot 뷰 선택-JSP/JSTL (0) | 2023.02.10 |
230210 Spring Boot 설치, 프로젝트 생성, DB연결 (0) | 2023.02.10 |
230210 SpringBoot 기초 (0) | 2023.02.10 |