spring boot 의 경로 맵

spring boot 에 thymeleaf 를 통합 한 후에 thymeleaf 의 기본 html 경 로 는 classpath: / templates 즉 resources / templates 라 는 것 을 알 게 되 었 습 니 다. 이 경로 아래 의 정적 페이지 를 어떻게 방문 합 니까?만약 우리 가 한 페이지 를 hello. html 로 방문 할 것 이 라 고 가정 합 니 다.
DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Titletitle>
head>
<body>
<h1>hell spring boot!!h1>
body>
html>

이 페이지 는 templates 아래 에 있 습 니 다. 물론 application. properties 파일 에서 기본 경 로 를 수정 할 수 있 습 니 다.
spring.thymeleaf.prefix=classpath:/templates

1. controller 의 방법 으로 이 페이지 로 바로 돌아 가기
@Controller
public class HelloController {
    @GetMapping("/hello")
    public String hello(){
  // thymeleaf hello html return "hello"; } }

 
2. WebMvcConfigure 인터페이스 에 있 는 addViewControllers 방법 으로 경 로 를 매 핑 합 니 다.
@Configuration
public class WebMvcConfig implements WebMvcConfigurer{
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //         Controller           view       
        //                                           
        registry.addViewController("/hopec").setViewName("hello");
    // } }

좋은 웹페이지 즐겨찾기