Springboot + Freemarker(一)


Maven pom文件配置
 1 
 2         org.springframework.boot
 3         spring-boot-starter-parent
 4         2.1.5.RELEASE
 5          
 6     
 7 
 8     
 9         1.8
10     
11 
12     
13         
14             org.springframework.boot
15             spring-boot-starter-freemarker
16         
17         
18             org.springframework.boot
19             spring-boot-starter-web
20         
21 
22         
23             org.springframework.boot
24             spring-boot-starter-test
25             test
26         
27     
28 
29     
30         
31             
32                 org.springframework.boot
33                 spring-boot-maven-plugin
34             
35         
pom.xml

Freemarker 页面目录配置

1 spring:
2   mvc:
3     view:
4       prefix: /templates/
5       suffix: .ftl
application.yml

Controller 编写

 1 @Controller
 2 @RequestMapping("test")
 3 public class DemoController {
 4 
 5 
 6     @RequestMapping("toDemo")
 7     public String toDemo(ModelMap modelMap){
 8         List arr = new ArrayList();
 9         arr.add("狗贼");
10         arr.add("企鹅");
11 
12         modelMap.put("arr",arr);
13 
14         return "demo";
15     }
16 
17 }
DemoController.java

ftl 页面

 1  2 3 4 5         <#list arr as i>
 6 7 8 910
姓名
${i}
demo.ftl

输出结果: