首先 加入 freemaker 的依赖css
<!-- freemarker --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency>
而后在配置文件 application.properties 中增长html
spring.freemarker.allow-request-override=false spring.freemarker.cache=true spring.freemarker.check-template-location=true spring.freemarker.charset=UTF-8 spring.freemarker.content-type=text/html spring.freemarker.expose-request-attributes=false spring.freemarker.expose-session-attributes=false spring.freemarker.expose-spring-macro-helpers=false spring.freemarker.suffix=.html spring.freemarker.template-loader-path=classpath:/static/
在 src.main.resource 目录中 新建文件夹 staticjava
不要忘记加入到 Use as source Floderjquery
之后全部的html页面 css js 都放在这个文件夹里spring
先在里面建个img文件夹 和 templates 文件夹session
在 static/templates 中新建 main.fltapp
<!DOCTYPE html> <#macro head charset="utf-8" lang="zh-CN"> <html> <head> <title><#nested></title> </head> </#macro> <#macro body charset="utf-8" lang="zh-CN"> <body> <#nested> </body> </#macro> <#macro footer charset="utf-8" lang="zh-CN"> <!-- jQuery 2.2.3 --> <script src="../adminLTE/plugins/jQuery/jquery-2.2.3.min.js"></script> <#nested> </html> </#macro>
在 static 文件夹中创建 sayhello.html ide
<#include "templates/main.flt"/> <@head> Freemaker 测试中文 </@head> <@body> <img src="img/face.jpg" /> UserID:${user.id}<br /> UserName:${user.name}<br /> Age:${user.age}<br /> </@body> <@footer> <script> alert(123); </script> </@footer>
在 static/img 拷贝一个图片 起名face.jpgspring-boot
写好java 代码测试
@RequestMapping("/sayhello") public String sayhello(Map<String,Object> map){ User user = new User(); user.setId(133L); user.setName("shili"); user.setAge(11); map.put("user", user); return "sayhello"; }
搞定