In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to use Freemarker to build email templates in SpringBoot. I think it is very practical, so I share it with you. I hope you can get something after reading this article.
Introduce dependency
The first step, of course, is to introduce freemarker dependencies, as follows:
Org.freemarker freemarker creates a mail template
The next step is to create a mail template based on the HTML style we want. The template is a ftl file, as follows:
Hello, ${name} Children's shoes, welcome to the XXX family! Your onboarding information is as follows:
Work code ${workID} contract duration ${contractTerm} year contract start date ${beginContract?string ("yyyy-MM-dd")} contract due date ${endContract?string ("yyyy-MM-dd")} Department ${departmentName} position ${posName}
Hope that in the future, hand in hand!
The final display is as follows:
This style partner can adjust flexibly according to his own needs. There is one thing to note: because I have separated the front and rear, the webapp directory in the project doesn't matter to me anymore, and it doesn't make much sense to create it, so I put this mail template in the ftl directory under the resources directory.
Template parsing
With the template, I just need to pass the data into the template and parse the template ftl to html, as follows:
Configuration cfg = new Configuration (Configuration.VERSION_2_3_27); cfg.setClassLoaderForTemplateLoading (ClassLoader.getSystemClassLoader (), "ftl"); Template emailTemplate = cfg.getTemplate ("email.ftl"); StringWriter out = new StringWriter (); emailTemplate.process (employee,out)
Instead of the hassle of configuring freemarker in the SSM framework, here are a few lines of code:
1. Create a Configuration object based on the freemarker version number used
two。 There are several ways to set the template path. Because I put it in the resources directory, I use the setClassLoaderForTemplateLoading method.
3. Create a template and render it using the process method. The rendered html will be put into the variable out, and then we can send it directly in the email.
This is how to use Freemarker to build mail templates in SpringBoot. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.