하루에 한가지

thymeleaf 추가 본문

카테고리 없음

thymeleaf 추가

너도 2024. 2. 23. 20:40

pom.xml 추가

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

 

구동을 해보면

 

Cannot find template location: classpath:/templates/ (please add some templates, check your Thymeleaf configuration, or set spring.thymeleaf.check-template-location=false)

 

위와 같은 메시지가 뜬다.
라이브러리는 잘 추가가 된 것을 확인 할 수 있고.

해당 디렉토리에 아무 html을 추가하면 해당 로그가 사라지는 것을 확인할 수 있다.

 

contoller까지 추가해서 연결을 해보면.

package com.urbug2.web.sample.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("samples")
public class SampleThymeleafController {

	@RequestMapping(method=RequestMethod.GET)
	public String sample() {
		return "samples"; // /main/resources/templates/samples.html
	}
	
}

 

/main/resources/templates/samples.html

경로에 임의 파일을 추가하면

 

<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Sample</title>
</head>
<body>
Sample Pages
</body>
</html>

 

 

 

정상적으로 연결된 것을 확인할 수 있다.

Comments