码迷,mamicode.com
首页 > 编程语言 > 详细

Spring Boot 初体验(10)使用使用freemarker

时间:2018-11-02 01:49:26      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:cti   hid   ping   map   request   mapping   star   pack   span   

一:在pom.xml中引入freemarker

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

关于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

代码:

controller:

技术分享图片
package com.mt.controller;

import java.util.Date;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/thymeleaf")
public class ThymeleafController {
    @RequestMapping("/hello")
    public String hello(Map<String, Object> map) {
        map.put("date", new Date());
        return "thymeleafDemo";
    }

    @RequestMapping("/demo")
    public String demo(Map<String, Object> map) {
        map.put("demo", "freemarker  demo ");
        return "freemarkerDemo";
    }

    @RequestMapping("/rr")
    public String rr(Map<String, Object> map) {
        map.put("demo", "freemarker  demo ");
        return "rr";
    }
}
View Code

ftl:

<!DOCTYPE html>
    <head>
        <title>Hello World!</title>
    </head>
    <body>
        <h1>Hello.v.2</h1>
        <p>${demo}</p>
    </body>
</html>

技术分享图片

技术分享图片

 

Spring Boot 初体验(10)使用使用freemarker

标签:cti   hid   ping   map   request   mapping   star   pack   span   

原文地址:https://www.cnblogs.com/kuangyefeige/p/9893248.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!