速度模板 - 新线 [英] Velocity Templates - New Line

查看:102
本文介绍了速度模板 - 新线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Apache的Velocity引擎和自定义模板。

事实上,我无法生成带有相应换行符的String。
我几乎尝试了所有我发现的东西,例如使用$ esc.n和$ esc.newline(我已经在我的项目中使用了逃生工具)但似乎我目前使用的版本没有支持它(1.4),检查是否可以使用'\ n','\\ n'甚至'\\\ n',但同样的事情。

I've been working with Apache's Velocity engine and a custom template.
The thing is, that I haven't been able to generate a String with the corresponding line breaks. I tried almost everything that I found, such as using $esc.n and $esc.newline (I'm already using escape tools on my project) but it seems that the version I'm currently using doesn't support it (1.4), checked if putting '\n', '\\n' and even '\\\n' would work, but same thing.

有没有人对此有任何解决方案?

Does anyone have any solution to this?

推荐答案

我们有换行问题并最终在VelocityContext上放置一个属性:

We had issues with newlines and ended up putting a property on the VelocityContext:

VelocityContext ctx = new VelocityContext();
ctx.put("newline", "\n");

然后,无论我们需要使用换行符,我们都会引用上下文变量:

Then, wherever we needed to use a newline, we would reference the context variable:

$newline

我们在需要用< br />替换字符串中的换行符的情况下使用它。

We use this in cases where we need to replace newlines in a string with <br />.

这篇关于速度模板 - 新线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆