Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to integrate Freemarker template engine based on SSM

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "how to integrate Freemarker template engine based on SSM", the content is easy to understand, clear, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "how to integrate Freemarker template engine based on SSM" this article.

Introduction to FreeMarker

FreeMarker is a template engine written in the Java language that generates text output based on templates. FreeMarker has nothing to do with the Web container, that is, when Web is running, it does not know about Servlet or HTTP. It can not only be used as a presentation layer implementation technology, but also can be used to generate XML,JSP or Java text and so on.

It can completely separate the presentation layer from the business logic.

In the process of using JSP development, we have found that there are a lot of code with business logic in the page, which makes the content of the page messy, which becomes very difficult in the later stage of a large number of modifications and maintenance.

The principle of FreeMarker is: template + data model = output, the template is only responsible for the performance of the data on the page, does not involve any logic code, and all the logic is handled by the data model. The output that the user finally sees is created after the template and the data model are merged.

Background

Under the general trend of separation of front and rear ends, the dependence and coupling between front end and background should be reduced as much as possible in the process of project development, and ajax should be used for interaction between front end and background as far as possible. however, ajax of the whole station is not conducive to website SEO, so template engine is introduced to minimize the dependence of front end on back end. Under SSM architecture, Thymeleaf template engine is generally recommended under Freemarker,Spring Boot architecture.

SSM integrated Freemarker

1. Introduce dependency

Org.freemarker freemarker 2.3.29

2. Spring mvc core configuration file, spring-mvc.xml, add related configuration

5 UTF-8 UTF-8 yyyy-MM-dd HH:mm:ss HH:mm:ss 0.#### true,false true auto_detect UTF-8

2. Call the template in Controller to render the page effect.

RequestMapping (value = "/ index", method = RequestMethod.GET) public String index (Model model) {model.addAttribute ("fm", "2020"); return "index";}

Call template engine, jump to / WEB-INF/view/index.ftl, pass data, render page

3. The definition template file is named index.ftl.

The home page ${fm} above is all the content of the article "how to integrate Freemarker template engine based on SSM". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report