资源

  • MVNRepository
  • 官方参考手册
  • FreeMarker 中文参考手册(对应版本:v2.3.23,仅做参考使用)
  • 中文手册(对应版本:v2.3.28)

    POM

    1. <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-freemarker -->
    2. <dependency>
    3. <groupId>org.springframework.boot</groupId>
    4. <artifactId>spring-boot-starter-freemarker</artifactId>
    5. </dependency>

    使用

    新建 src/main/resources/templates 文件夹,添加 index.ftlh 文件:
  1. <!doctype html>
  2. <html class="no-js" lang="zh">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta http-equiv="x-ua-compatible" content="ie=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>Foundation Starter Template</title>
  8. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.5.3/css/foundation.min.css" integrity="sha256-xpOKVlYXzQ3P03j397+jWFZLMBXLES3IiryeClgU5og=" crossorigin="anonymous" />
  9. </head>
  10. <body>
  11. <h1>Hello, world!</h1>
  12. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
  13. <script src="https://cdnjs.cloudflare.com/ajax/libs/what-input/5.1.3/what-input.min.js" integrity="sha256-bj9uUXCtgWia8MCh9s6lkvAbenPi2xgxdyH5qfPrAVk=" crossorigin="anonymous"></script>
  14. <script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.5.3/js/foundation.min.js" integrity="sha256-/PFxCnsMh+nTuM0k3VJCRch1gwnCfKjaP8rJNq5SoBg=" crossorigin="anonymous"></script>
  15. <script>
  16. $(document).foundation();
  17. </script>
  18. </body>
  19. </html>

在控制器中返回视图:

  1. @RequestMapping(value = "/", method = RequestMethod.GET)
  2. public String index() {
  3. return "index";
  4. }