이전에는 jsp 파일에서만 스프링 MVC를 사용했습니다. 모든 것이 잘 작동했습니다. 하지만 오늘은 처음으로 html 파일을 사용하려고 시도하자 즉시 문제가 발생했습니다. 어떤 이유로 html 파일의 내용이 내 브라우저에 표시되지 않습니다. 아래는 구성입니다.html로 봄 MVC 사용하기
구성 :
@SpringBootApplication
@ComponentScan("newTestPackage")
public class Config extends WebMvcConfigurerAdapter {
public static void main(String[] args) throws Exception {
SpringApplication.run(Config.class, args);
}
@Bean
public ViewResolver jspViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".html");
resolver.setExposeContextBeansAsAttributes(true);
return resolver;
}
}
컨트롤러 :
@Controller
public class IndexController {
@RequestMapping(value = "/")
public String index() {
return "index";
}
}
HTML :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
Hello World
</body>
</html>
JSP 버전 잘 작동합니다. 는 그래서 그 폴더 내부에 index.html
을 배치 JSP 페이지를 찾을 수됩니다 이유를 이해하고 표시 한 ('찾을 수 없음'상태) 기본적으로
스프링 부트를 사용하고 있습니까? (그렇지 않다면, Spring Boot를 사용하십시오.) Boot를 사용하면 일반적으로 템플릿을'src/main/resources/templates'에 넣을 것입니다. – chrylis
예, 있습니다. src/main/resources/templates에 index.html을 제거하면 결과는 동일합니다. – sva605
글쎄요, html은 스프링 부트를 포함하지 않는 일반적인 스프링 MVC 설정에서 잘 작동한다는 것입니다. 그러나 html과 Spring Boot를 결합하는 것은 여전히 미스터리입니다. – sva605