《SpringBoot2.X心法总纲》 html
(本篇博客已于2019-08-28优化更新)spring
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency>
spring: freemarker: allow-request-override: false cache: true check-template-location: true charset: UTF-8 content-type: text/html expose-request-attributes: false expose-session-attributes: false expose-spring-macro-helpers: false suffix: .html profiles: active: dev
若是你使用的是ftl后缀,那么更改suffix为ftl,或者不用写,默认是ftl,若是你用html开发,那么suffix标注htmlsession
@GetMapping(value = "/test2") public String test2(ModelMap modelMap){ modelMap.put("name","木九天"); return "/helloworld"; }
在resources/template下建立helloworld.htmlapp
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> ${name} </body> </html>
5.1 :使用freemaker的时候,咱们在controller返回的是一个路径,同时咱们也使用了ModeMap,咱们在ModeMap添加了数据,而后返回路径到具体html页面,${name} 就是咱们ModeMap里面的数据,但愿你们不要迷惑输出结果:木九天怎么来的! 5.2: 返回具体页面/找对应页面的时候,千万不能使用@RestController 和@ResponseBody,由于使用它们以后返回的是一个字符串而不是一个具体页面了,谨记。