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)