我应该使用哪种 Java 模板系统来生成电子邮件?

发布于 2024-07-25 22:53:19 字数 408 浏览 4 评论 0原文

我有一个网站,使用 JSP 作为其视图技术(以及底层的 Spring MVC)。 不幸的是,JSP 对于任何不涉及 HTTP 会话的东西来说使用起来都很痛苦。 我希望能够偶尔向我的用户发送一些电子邮件,并且我想使用类似 JSP 的东西来呈现电子邮件的内容。 我知道的技术包括:

  • JSP——我认为它可以被迫为这类事情工作。 最糟糕的情况是,我可以从我自己的网络服务器请求该页面并将其呈现为电子邮件(呃!)
  • Velocity - 我听说过有关此的好消息,并且正在倾向于它。
  • StringTemplate——看起来不错,但我担心一年内没有新版本发布。

Java 系统中是否有首选的模板技术? 人们通常会推荐 Velocity 吗? 有没有使用 JSP 来完成更通用任务的好方法?

I have a website that uses JSP as its view technology (and Spring MVC underneath). Unfortunately, JSP is just a pain to use for anything that doesn't involve an HTTP session. I would like to be able to occasionally send my users some email, and I want to use something JSP-like to render the email's contents. Technologies I'm aware of include:

  • JSP -- It can be forced to work for this sort of thing, I think. Very worst case, I could request the page from my own webserver and render that into an email (ugh!)
  • Velocity -- I've heard good things about this one, and am leaning towards it.
  • StringTemplate -- Looks okay, but I'm worried that no new releases have come out in a year.

Is there a preferred technology for templating in a Java system? Would folks generally recommend Velocity? Is there a good way to use JSP for more generic tasks?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

戏剧牡丹亭 2024-08-01 22:53:20

我经常使用 Freemarker 来制作电子邮件模板,它效果很好并且易于使用。

I used Freemarker a lot for e-mail templating and it worked great and was easy to use.

梦情居士 2024-08-01 22:53:20

你应该选择 Velocity。 它很容易学习,并且依赖性和实现足迹都很低,特别是在使用 Spring 时。

但是,如果这只是一个用例,您应该坚持使用字符串,除非您没有时间进行实验;)

You should go with Velocity. It's easy to learn and has a low dependency and implementation footprint, especially when using Spring.

But, if it's just one Use Case, you should stick with the String and unless you have no time for experiments ;)

爱*していゐ 2024-08-01 22:53:20

我已经多次成功使用 StringTemplate 来发送电子邮件。 它很简单并且非常容易集成。

StringTemplate 的简单性使得可以直接替换消息的不同部分,例如主题。 不知道如何使用 Velocity 来做到这一点。

我不会担心发布频率——也许它已经足够好了,不需要再积极开发了。

I have used StringTemplate several times successfully for sending emails. It is simple and extremely easy to integrate.

The simplicity of StringTemplate makes it straightforward to substitute different parts of the message, for example, subject. Not sure how to do this with Velocity.

I wouldn't worry about the release frequency -- maybe it is just good enough and doesn't need to be actively developed any more.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文