• (016)Spring Boot之如何使用freemarker


      springboot支持freemarker,需要在pom.xml文件中添加以下依赖:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-freemarker</artifactId>
    </dependency>

      freemarker文件的默认路径是:classpath:/templates/,如下:

       测试类如下:

    package com.edu.spring.springboot;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    @Controller
    public class AccountController {
    
        @RequestMapping("/reg")
        public String reg(){
            return "/reg";
        }
        
    }

      浏览器输入:http://127.0.0.1:8080/reg即可跳转到 reg.ftl页面

      修改freemarker的默认路径,在application.properties文件中添加spring.freemarker.templateLoaderPath属性,可以配置多个,逗号分隔,如下:

    spring.freemarker.templateLoaderPath=classpath:/ftl/,classpath:/ftl2/

      目录结构如下:

      测验类如下:

    package com.edu.spring.springboot;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    @Controller
    public class AccountController {
    
        @RequestMapping("/reg")
        public String reg(){
            return "reg";
        }
        
        @RequestMapping("/logout")
        public String logout(){
            return "logout";
        }
    }

      浏览器输入:http://127.0.0.1:8080/reg即可跳转到 reg.ftl页面

      浏览器输入:http://127.0.0.1:8080/logout即可跳转到 logout页面

  • 相关阅读:
    forEach
    Apache localhost和局域网ip地址访问
    数据库基础知识(必读)
    设计模式其他常见面试题
    设计模式学习
    简历书写注意事项
    计算机网络常见面试题二
    计算机网络常见面试题一
    分布式系统中的CAP 理论
    多线程常见面试题一
  • 原文地址:https://www.cnblogs.com/javasl/p/11918172.html
Copyright © 2020-2023  润新知