前提:
開發工具:idea
框架:spring boot、maven
1、pom文件添加依賴
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> <version>1.4.1.RELEASE</version> </dependency>
2、新建spring web項目,會自動生成application.properties.
使用application.properties配置文件之后,spring boot啟動時,會自動把配置信息讀取到spring容器中,並覆蓋spring boot的默認配置。
3、在配置文件中,設置以下兩個參數
#設定ftl文件路徑
spring.freemarker.template-loader-path=classpath:/templates
#設定靜態文件路徑,js,css等
spring.mvc.static-path-pattern=/static/**
controller跳轉頁面如下:
templates/action/list.ftl頁面