zoukankan      html  css  js  c++  java
  • (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页面

  • 相关阅读:
    音频处理入门笔记
    python对象-多态
    python对象的不同参数集合
    python多重继承的钻石问题
    python对象的多重继承
    python类继承的重写和super
    Python继承扩展内置类
    python对象继承
    Python模块与包
    Pyhton对象解释
  • 原文地址:https://www.cnblogs.com/javasl/p/11918172.html
Copyright © 2011-2022 走看看