一、pom依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
</dependencies>
二、controller类
@Controller
public class userController {
@RequestMapping("/show")
public String index(Model model) {
model.addAttribute("name", "涵予");
return "show";
}
}
三、全局配置文件
server.port=8081
spring.application.name= houses-service
#设置模板后缀名
spring.freemarker.suffix=.ftl
#设置文档类型和页面编码格式
spring.freemarker.content-type=text/html; charset=utf-8
#设置页面缓存
spring.freemarker.cache=false
#设置静态文件路径。js,css等
spring.mvc.static-path-pattern=/static/**
四、html
<!DOCTYPE>
<html>
<head>
<title>freemark</title>
</head>
<body>
<h1>Hello${name}welcome to freemark!</h1>
</body>
</html>
五、启动类
@SpringBootApplication(scanBasePackages={"com.freemarker.controller"})
public class freemarkerTest {
public static void main(String[] args) {
SpringApplication.run(freemarkerTest.class, args);
}
}
六、测试结果