springboot通過controller訪問resource/template文件下的模板文件報404

1.導入依賴:

<!--訪問模板文件-->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
		

2.application.properties文件配置:

#配置模板引擎
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.cache=false

3.controller類和html模板文件:

controller:

@Controller
@RequestMapping("/index")
public class HomeController {
    @RequestMapping("/hello")
    public String index() {
        return "home";
    }
}

resource/template 文件夾下的home.html文件:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
</head>
<body>
hello springboot
</body>
</html>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章