Freemarker
https://freemarker.apache.org/
springboot中freemarker的默认配置
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.ftl
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Freemarker测试</title>
</head>
<body>
<h1>姓名:${name}</h1>
</body>
</html>
web处理器
添加一个springmvc控制器
@Controller
public class IndexController {
@RequestMapping({"","index"})
public String index(Model model){
model.addAttribute("name", "哈哈哈");
return "index";
}
}
查看效果
启动项目后,访问 localhost:8080
Thymeleaf
参考 https://gitee.com/yimingkeji/springboot/tree/master/thymeleaf
来源:oschina
链接:https://my.oschina.net/u/4018042/blog/2994924