崛起于Springboot2.X之前端模版freemaker(23)
生活随笔
收集整理的這篇文章主要介紹了
崛起于Springboot2.X之前端模版freemaker(23)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
為什么80%的碼農都做不了架構師?>>> ??
1、配置文件
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-freemarker</artifactId> </dependency>添加依賴
spring:freemarker:allow-request-override: falsecache: truecheck-template-location: truecharset: UTF-8content-type: text/htmlexpose-request-attributes: falseexpose-session-attributes: falseexpose-spring-macro-helpers: falsesuffix: .htmlprofiles:active: dev? ? 如果你使用的是ftl,那么更改suffix為ftl,或者不用寫,默認是ftl,如果你用html開發,那么suffix標注html
2、編寫controller
@GetMapping(value = "/test2") public String test2(ModelMap modelMap){modelMap.put("name","木九天");return "/helloworld"; }3、創建html
????在resources/template下創建helloworld.html
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Title</title> </head> <body> ${name} </body> </html>4、測試
5、疑惑解惑
? ? 5.1 :使用freemaker的時候,我們在controller返回的是一個路徑,同時我們也使用了ModeMap,我們在ModeMap添加了數據,然后返回路徑到具體html頁面,${name} ?就是我們ModeMap里面的數據,希望大家不要迷惑輸出結果:木九天怎么來的!
?????5.2: 返回具體頁面/找對應頁面的時候,千萬不能使用@RestController 和@ResponseBody,因為使用它們之后返回的是一個字符串而不是一個具體頁面了,謹記。
?
?
轉載于:https://my.oschina.net/mdxlcj/blog/1859328
總結
以上是生活随笔為你收集整理的崛起于Springboot2.X之前端模版freemaker(23)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle 数据库备份恢复
- 下一篇: Spring Cloud【使用jenki