내가 SpringBoot 1.5.9 사용에 의해 발견 src/main/resources/static/index.html
를 작성하지 index.html을 :봄 부팅 - 컨트롤러
<!DOCTYPE html><html><head><meta charset="utf-8"/>
<title>Home</title></head>
<body><h2>Hello World!!</h2></body>
</html>
:
@Controller
public class MyController {
@RequestMapping("/")
public String home(Model model) {
System.out.println("In MyController!!!");
return "index";
}}
그러나
내가에서 내 주요 방법을 실행 한 후 :
@SpringBootApplication
public class MySpringBoot2Application {
public static void main(String[] args) {
SpringApplication.run(MySpringBoot2Application.class, args);
}
}
내가 내 브라우저를 : 01,237 내가 직접 페이지에 액세스하려고하면, 허용 목록 라벨이 오류 페이지가-이 예기치 않은 오류 (type=Not Found, status=404)
했지만 -이 작품을 잘 : 36,996,526, 나는 점점 오전 http://localhost:8080/index.html
SpringBoot 문서 정적 콘텐츠를 기반으로 src/main/resources/static/
이하를 렌더링해야합니다. 폴더 src/main/resources/templates/
을 만들고 거기에 index.html
을 넣고 spring-boot-startter-thymeleaf 의존성을 pom.xml에 포함하면 모든 것이 잘 작동합니다. 그러나 나는 src/main/resources/static/index.html 의이 기본 렌더링이 작동하지 않는 이유에 대해 의아해합니다. 어떤 도움을 주셔서 감사합니다.
당신의'MyController' 클래스를 제거, 그것없이 작동 : 컨트롤러 MyController에 파일 확장자를 지정해야 –