Springboot + Freemarker(一)
Maven pom文件配置
2
demo.ftl
1pom.xml2 7 8org.springframework.boot 3spring-boot-starter-parent 42.1.5.RELEASE 56 9 11 121.8 1013 28 2914 17org.springframework.boot 15spring-boot-starter-freemarker 1618 21 22org.springframework.boot 19spring-boot-starter-web 2023 27org.springframework.boot 24spring-boot-starter-test 25test 2630 31 32 35org.springframework.boot 33spring-boot-maven-plugin 34
Freemarker 页面目录配置
1 spring: 2 mvc: 3 view: 4 prefix: /templates/ 5 suffix: .ftlapplication.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 | 姓名 | 4
| ${i} | 8
输出结果: