速度设置指令中的新行

发布于 2024-09-18 09:44:30 字数 289 浏览 2 评论 0原文

如何使用 set 在速度模板中附加换行符?这是行不通的。

#(set $some = "$a \n $b")

按字面打印 \n。

这样做也不起作用:

VelocityContext context = new VelocityContext();
context.put("esc", new EscapeTool());
Velocity.evaluate(context, writer, "LOG", template);

How do you append a newline in velocity template using set? This does not work.

#(set $some = "$a \n $b")

Prints literally \n.

Doing this also does not work :

VelocityContext context = new VelocityContext();
context.put("esc", new EscapeTool());
Velocity.evaluate(context, writer, "LOG", template);

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

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

发布评论

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

评论(2

空城之時有危險 2024-09-25 09:44:30

您可以使用 EscapeTool 用于此:

#set($some = $a + $esc.n + $b)

如何初始化工具:

ToolManager velocityToolManager = new ToolManager();
velocityToolManager.configure("velocity-tools.xml");
VelocityContext context = new VelocityContext(velocityToolManager.createContext());

您可以从 此处(它也包含在工具 jar 中)并启用您需要的工具。

You can use $esc.n or its synonym $esc.newline from the EscapeTool for this:

#set($some = $a + $esc.n + $b)

How to init tools:

ToolManager velocityToolManager = new ToolManager();
velocityToolManager.configure("velocity-tools.xml");
VelocityContext context = new VelocityContext(velocityToolManager.createContext());

You can get default velocity-tools.xml from here (it's also included into tools jar) and enable tools that you need.

烟花肆意 2024-09-25 09:44:30

您知道,在现代版本的 Velocity 中,您只需插入换行符即可。

#set( $haslinebreak = "this has
a line break" )

You know, in modern versions of Velocity you just put the line break in.

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