如何在 freemarker 中将整数转换为字符?

发布于 2024-12-23 09:13:57 字数 157 浏览 1 评论 0原文

我正在迭代 0-26 的列表,并希望获得每个字母对应的字母。例如,0 会给我字母“A”等等。

我知道在java中我可以说: 字符 A = (字符)65; 这将从我的 65 整数中得到一个“A”。

但是我如何在前端用 freemarker 做到这一点,我不知道?

I am iterating over a list from 0-26, and would like to get the corresponding letter with each. For example, 0 will give me letter 'A' and so on.

I know that in java I can say:
char A = (char)65;
and that will give me an 'A' from my 65 integer.

But how can i do this on the front-end with freemarker, I have no clue?

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

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

发布评论

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

评论(1

独﹏钓一江月 2024-12-30 09:13:57

更新:在 FreeMarker 2.3.22 中,您可以仅使用 (i + 1)?upper_abc 表达式。 (如果 i 是从 0 开始的,则需要 + 1。)

不幸的是,FreeMarker 还没有相应的运算符。尽管仍然可以纯粹在 FreeMarker 中通过构建使用 \x 转义然后 ?eval 的字符串文字来实现此目的,但这将非常丑陋且效率低下。因此,目前正确的解决方案是编写自己的 TemplateMethodModelEx,并将其放入 #import-et 实用程序库(如果有的话)中,并使用 <#分配 numToChar = 'com.example.NumToCharMethod'?new()>,或将其添加为配置中的共享变量。

Update: In FreeMarker 2.3.22 you can just use the (i + 1)?upper_abc expression. (The + 1 is needed if i is 0-based.)

Unfortunately, FreeMarker has no operator for that, yet. Although it's still possible to achieve this purely in FreeMarker by building a string literal that uses a \x escape and then ?eval it, that would be very ugly and inefficient. So the proper solution for now is to write your own TemplateMethodModelEx, and put it into #import-et utility library (if you have one) with <#assign numToChar = 'com.example.NumToCharMethod'?new()>, or add it as shared-variable in the Configuration.

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