Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 10 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(8)
是的。 为了完整起见,还有其他引人注目的库,例如
yes, it is. For the sake of completeness there are other compelling libraries like:
几年前,我编写了一个用于发送发票通知的应用程序。 我使用 Velocity 来创建电子邮件的实际内容。 传输由 James 提供,电子邮件服务器由 Apache 提供。 该应用程序每天发送数十万封个性化电子邮件。
Velocity 没有给我带来任何问题,但是在使用 FreeMarker 有了一些经验后,我现在可能会选择 FreeMarker。
A number of years ago I've written an application for sending invoice notifications. I used Velocity to create the actual contents of the e-mails. The transport was provided by James, the e-mail server by Apache. This application sends out 10s of thousands of personalised e-mails each day.
Velocity did not give me any problems, but having had some experience with FreeMarker, I would probably pick FreeMarker now.
我是 Pebble 模板引擎的作者,我认为这正是您正在寻找的。
I'm the author of Pebble templating engine which I think is exactly what you're looking for.
仅供记录,您还可以使用许多其他模板引擎,不仅适用于电子邮件。 在我从事的大多数项目中,都使用了 Velocity,当不使用 Velocity 时,就会使用 Freemarker。
Just for the record, there are many other template engines that you can use, and not only for email. In most projects that I've worked on, Velocity was used and when it wasn't Velocity, it was Freemarker.
如果您处于 Servlet 环境中,您可能想要研究的另一个选项(尽管可能不会)是使用 JSP。 在大多数情况下,我不会推荐这样做,因为设置此设置确实需要大量的前期工作。
然而,这在我们的环境中是一个有用的解决方案,我们有一群已经熟悉 JSP 语法和自定义标签的 Web 开发人员。 很高兴能够让他们直接处理电子邮件内容,而无需学习另一种模板语言(尽管我确信 FreeMarker 可能并不难学)。 这种方法还允许我们在电子邮件内容中重复使用一些自定义标签。
Another option you may want to look into (though probably not) is to use JSP, if you are in a Servlet environment. For the most part, I wouldn't recommend this since it's really quite a lot of up front work to get this set up.
However, this was a useful solution in our environment, where we have a bunch of web developers who are already familiar with JSP syntax and custom tags. It was nice to be able to have them work on the e-mail contents directly without having to learn another templating language (though I'm sure FreeMarker probably isn't that hard to learn). This approach also allows us to re-use some of our custom tags in e-mail content.
在我开始做我的电子邮件模板之前,我想我会问我的朋友,然后我想到了使用 JSP 引擎进行模板化的想法(如果您在 servlet 环境中)。 我发现这个想法原创且完美满足我的需求,因为我在 GAE 下,并且向 GAE 添加 jar 是一个非常昂贵的决定(对性能的影响)
以及我如何到达该链接(最初的想法)
https://stackoverflow.com/a/458088/2033675
所以我放了一个链接来指导如何操作Java电子邮件模板的建议?
当然,以防有人有与我相同的限制做。
最好的
Before I started doing my email templating, I thought I will ask my gFriend, and I came across the idea of using the JSP engine for templating (if you're in a servlet environment). I found the idea original and perfect for my needs since I'm under GAE and adding jar to GAE is a very costly decision (impact on performance)
And how I came to that link (the original idea)
https://stackoverflow.com/a/458088/2033675
So I put a link to how to do it Suggestions for Java email templating?
naturally in case someone will have the same constrains as I do.
Best
在企业领域,许多人使用声纳或 PMD 等工具来查看代码复杂性。 我不知道其中之一是否支持任何模板库。 然而,我在野外审查过的模板的复杂程度非常高,我真的很想在我的代码中避免这种情况。 我尝试重构其中的一些,尽管取得了一些成功,但结果却并不令人满意。 几天前,我使用 Snippetory< 将 2kLoC 模板重构为 150 行模板代码和一个新的 java 类中大约 1.5kLoC 逻辑/a>. 当然,这仍然需要一些工作来匹配指标,但现在可以实现可维护的代码。 片段模板通过将数据绑定逻辑移出模板,提供了极大的关注点分离。 作为奖励,模板的可重用性更高。 另一方面,逻辑和代码之间的绑定也需要一些代码。 最终代码量没有太大变化,但可读性却大幅提升。
对于企业业务,我推荐 Snippetory。
In the enterprise sector many people haveuse tools like sonar or PMD to have a look on code complexity. I don't know if one of these supports any templating library. However, the level of complexity of templates I've reviewed in the wild was on a high niveau, I'd really like to prevent in my code. I tried to refactor some of them, and even though I made some success the results were never satisfying. Some days ago I refactored a 2kLoC template to 150 lines of template code and about 1.5kLoC logic in a new java class using Snippetory. Of course this left still some work to match out metrics, but now it's possible to achieve maintainable code. Snippetory templates provide a great separation of concerns by moving the data binding logic out of the template. As a bonus the template gets more re-useable. On the other hand the binding between logic and code requires some code, too. In the end te amount of code didn't change much, but readability increased dramatically.
For the enterprise business I'd recomment Snippetory.
Freemarker 效果很好,而且功能非常强大。 Velocity 的语法更简单,功能稍弱,但宽容得多。 nulls(未填充的变量)。
两者我都用过,而且 Velocity 非常容易上手。 Freemarker(尽管其实施更为严格)在“正确性”和设施方面提供了更多功能。
Freemarker works well, and is very powerful. Velocity has a simpler syntax, is somewhat less powerful, and is a lot more forgiving wrt. nulls (variables not being populated).
I've used both, and Velocity is very easy to get started with. Freemarker (despite its stricter implementation) offers a lot more in terms of 'correctness' and facilities.