Spring Boot Starter Series five (use of freemarker templates)

Source: Internet
Author: User

Use of Freemarker templates

Freemarker is a template engine: a generic tool that is based on templates and data to be changed, and used to generate output text (HTML pages, e-mail, configuration files, source code, etc.). It is not intended for end-users, but a Java class library, a component that programmers can embed into the products they develop.
Freemarker is free, based on the Apache License 2.0 release. The template is written as Freemarker template Language (FTL), which is a simple, dedicated language. You need to prepare the data to be displayed in a real programming language, such as database queries and business operations, after which the template displays the data that has been prepared. In the template, it is used primarily to show the data, but outside of the template, notice what data to show.

Use method; I. Introduction of dependency in Pom.xml
<dependency>    <groupId>org.springframework.boot</groupId>    <artifactId> Spring-boot-starter-freemarker</artifactid></dependency>
Second, in the Application.properties configuration Freemarker
############################################################## freemarker####################################### ##################### #spring. freemarker.template-loader-path=classpath:/templatesspring.freemarker.cache= falsespring.freemarker.charset=utf-8spring.freemarker.check-template-location= truespring.freemarker.content-type=text/htmlspring.freemarker.expose-request-attributes= Truespring.freemarker.expose-session-attributes=truespring.freemarker.request-context-attribute= Requestspring.freemarker.suffix=.ftl
III. Create a INDEX.FTL file for displaying data on the browser side
<! DOCTYPE html>

Iv. creating a controller for returning data to the front-end page

  

/** * @author OYC * @Title: * @Description: * @date 2018/6/1323:15 */@Controller @requestmapping ("FTL") public class Freemar Kercontroller {    @Autowired    private Resource Resource;    @RequestMapping ("/index") public    String index (Modelmap map) {        Map.addattribute ("resource", Resource);        return "Freemarker/index";    }}

Six, in the browser to access the corresponding address, you can display the interface we guessed:

Spring Boot Starter Series five (use of freemarker templates)

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.