Springboot How to use the Freemarker template engine

Source: Internet
Author: User
1.Freemarker Introduction

Freemarker is one of the three major mainstream template engines, with jsp,velocity and called the "Three Musketeers". 2.Freemarker Integration Solutions

① adding dependencies in Pom.xml

<!--freemarker Dependent-
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
Configuration of ②freemarker in Application.properities

# Freemarker (freemarkerautoconfiguration)
Spring.freemarker.allow-request-override=false  
Spring.freemarker.allow-session-override=false  
spring.freemarker.cache=true  
Spring.freemarker.check-template-location=true  
spring.freemarker.content-type=text/html  
Spring.freemarker.enabled=true  
Spring.freemarker.expose-request-attributes=false  
Spring.freemarker.expose-session-attributes=false  
spring.freemarker.expose-spring-macro-helpers=true  
Spring.freemarker.prefer-file-system-access=true  
spring.freemarker.suffix=.html
spring.freemarker.template-loader-path=classpath:/ftl/  
spring.freemarker.settings.template_update_delay=0  
Spring.freemarker.settings.default_encoding=utf-8  
spring.freemarker.settings.classic_compatible= True  
spring.freemarker.order=1  

Of course, the suffix of the access resources here can also be. FTL, this is the Orthodox Freemarker

Spring.freemarker.suffix=.ftl
Here the author of the HTML master better, so the preferred choice of HTML;

③ Create the FTL directory under resources based on the path configuration and new test.html


The test.html code is as follows:

<! doctype>
④ Edit Test Controller

@RequestMapping ("Ftl/test") public
String TESTFTL (Modelmap model) {
    Model.addattribute ("name", " Freemarker template Engine ");
    return "Test";
}
Note that the outermost control layer annotations can only be used @ @controller;

⑤ Access Test


All right, I'm Zhang Xing Zhaoyuan. Welcome to the BO Master Technology Exchange Group, Group No.: 313145288





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.