给大家简单介绍一下springboot 集成FreeMarker
过程很简单,5分钟即可。
首先在项目中增添依赖spring-boot-starter-freemarker
pom文件代码如下:
4.0.0 com.dalaoyang springboot_freemarker0.0.1-SNAPSHOT jar springboot_freemarker springboot_freemarker org.springframework.boot spring-boot-starter-parent1.5.10.RELEASE UTF-8 UTF-8 1.8 org.springframework.boot spring-boot-starter-freemarkerorg.springframework.boot spring-boot-starter-weborg.springframework.boot spring-boot-devtoolsruntime org.springframework.boot spring-boot-starter-testtest org.springframework.boot spring-boot-maven-plugin
然后创建controller,代码如下:
package com.dalaoyang.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class TestController {
@RequestMapping("/test")
public String testFreemarker(ModelMap modelMap){
modelMap.addAttribute("msg", "Hello dalaoyang , this is freemarker");
return "freemarker";
}
}
application.properties如下
##端口号 server.port=8888 #设定ftl文件路径 spring.freemarker.template-loader-path=classpath:/templates #设定静态文件路径,js,css等 spring.mvc.static-path-pattern=/static/**
然后简单给大家介绍一下,目录结构
然后贴上ftl文件的代码,一定注意,是ftl!!!!!
写html文件是无法找到页面的。
FreeMarker
${msg}
然后启动项目,访问http://localhost:8888/ 即可看到以下页面,
源码下载 :大老杨码云



