英文:
How to use reserved character (#) as interpolation in freemarker
问题
我的数据模型包含一个名为user#的字段,如果我直接将它放在模板中,模板解析会失败,以下是示例。如何转义#字符或任何其他解决方案。在下面的示例中,abc是一个带有键user#的哈希映射。
<body>
<h1>欢迎 ${(abc['user#'])!}</h1>
英文:
My data model contains a field name as user#, If I put it directly in the template it fails to parse the template, example below. How to escape the # character or any other solution. Here in the example below abc is a hashmap with key user#
<body>
<h1>Welcome ${(abc.user#)!}</h1>
答案1
得分: 1
自从问题更新后:由于具有问题名称的变量毕竟不在顶层,您可以编写 abc['user#']
。
顶层变量的旧答案:您可以将其称为 .vars['user#']
。不幸的是,在2.3.30版本中还没有 \#
转义字符。
英文:
Updated for updated question: Since the variable with problematic name is not on top-level after all, you can write abc['user#']
.
Old answer for top-level variable: You can refer to it as .vars['user#']
. Unfortunately, there's no \#
escape as of 2.3.30.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论