如何在 freemarker 中将整数转换为字符?
我正在迭代 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新:在 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 ifi
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 ownTemplateMethodModelEx
, 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 theConfiguration
.