学习笔记 : Spring Boot整合FreeMarker
FreeMarker官方简介
Apache FreeMarker™ is a template engine: a Java library to generate text output (HTML web pages, e-mails, configuration files, source code, etc.) based on templates and changing data. Templates are written in the FreeMarker Template Language (FTL), which is a simple, specialized language (not a full-blown programming language like PHP). Usually, a general-purpose programming language (like Java) is used to prepare the data (issue database queries, do business calculations). Then, Apache FreeMarker displays that prepared data using templates. In the template you are focusing on how to present the data, and outside the template you are focusing on what data to present.
This approach is often referred to as the MVC (Model View Controller) pattern, and is particularly popular for dynamic web pages. It helps in separating web page designers (HTML authors) from developers (Java programmers usually). Designers won't face complicated logic in templates
, and can change the appearance of a page without programmers having to change or recompile code.
引入Maven依赖
1 | <!-- Web --> |
编写Controller
1 | package pers.huangyuhui.freemark.controller; |
编写FreeMarker页面
1 |
|
程序运行效果如下所示 :