《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,由於使用它們以後返回的是一個字符串而不是一個具體頁面了,謹記。