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