https://freemarker.apache.org/html
http://freemarker.foofun.cn/java
package org.springframework.boot.autoconfigure.freemarker; import java.util.HashMap; import java.util.Map; import org.springframework.boot.autoconfigure.template.AbstractTemplateViewResolverProperties; import org.springframework.boot.context.properties.ConfigurationProperties; @ConfigurationProperties( prefix = "spring.freemarker"//配置文件默認前綴 ) public class FreeMarkerProperties extends AbstractTemplateViewResolverProperties { public static final String DEFAULT_TEMPLATE_LOADER_PATH = "classpath:/templates/";//默認靜態資源位置 public static final String DEFAULT_PREFIX = "";//默認前綴 public static final String DEFAULT_SUFFIX = ".ftl";//默認後綴 private Map<String, String> settings = new HashMap(); private String[] templateLoaderPath = new String[]{"classpath:/templates/"}; private boolean preferFileSystemAccess = true; public FreeMarkerProperties() { super("", ".ftl"); } //省略... //其餘見父類 }
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency>
spring: freemarker: cache: false #生成環境可設置爲true template-loader-path: classpath:/static suffix: .ftl
在resource目錄下新建目錄 static,而後新建個文件 index.ftlgit
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Freemarker測試</title> </head> <body> <h1>姓名:${name}</h1> </body> </html>
添加一個springmvc控制器web
@Controller public class IndexController { @RequestMapping({"","index"}) public String index(Model model){ model.addAttribute("name", "哈哈哈"); return "index"; } }
啓動項目後,訪問 localhost:8080spring
參考 https://gitee.com/yimingkeji/springboot/tree/master/thymeleafapache