• SpringBoot整合Freemarker


    1、在工程新建文件夹templates

    路径:src/main/resources/templates

    在配置文件application.properties中新增FreeMarker配置

    ########################################################
    ###FREEMARKER (FreeMarkerAutoConfiguration)
    ########################################################
    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.prefix=
    #spring.freemarker.request-context-attribute=
    #spring.freemarker.settings.*=
    spring.freemarker.suffix=.ftl
    spring.freemarker.template-loader-path=classpath:/templates/
    #comma-separated list
    #spring.freemarker.view-names= # whitelist of view names that can be resolved

    2、Freemarker的文件格式是.ftl

    3、pom.xml中引入依赖

    <!-- 引入freeMarker的依赖包. -->
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-freemarker</artifactId>
    </dependency>

    4、创建一个controller接口,controller的注解要用@Controller【跳转页面】不能用@RestController【返回JSON数据】

      @RequestMapping("/index")
        public String index(Map<String, Object> map) {
            map.put("name","美丽的天使...");
           return "index";
        }

    5、写一个index.ftl文件

    <!DOCTYPE html>
    <html>
    <head lang="en">
    <meta charset="UTF-8" />
    <title>首页</title>
    </head>
    <body>
          ${name}
    <#if sex=="1"><#else if sex=="2"><#else>
            其他      
          
          </#if>      
         <#list userlist as user>
           ${user}
         </#list>
    </body> 
    </html>
  • 相关阅读:
    [Windows Azure] Windows Azure Web Sites, Cloud Services, and VMs: When to use which?
    [Windows Azure] Windows Azure Execution Models
    [Windows Azure] Load Testing in Windows Azure
    [Windows Azure]The Autoscaling Application Block
    [Windows Azure]Windows Azure Identity
    [Windows Azure] Data Management and Business Analytics
    alienware Win8 系统安装
    Navisworks Addin 插件集成
    Navisworks 2014 Api 简单的使用
    Winform简单调用WebApi
  • 原文地址:https://www.cnblogs.com/yuhuiqing/p/10693113.html
Copyright © 2020-2023  润新知