我在Spring上下文中有简单的Velocity配置(根据官方的Spring文档)并且工作正常.如何使用Apache FOP配置/集成它并生成pdf文档?我会感激一些例子.
<!-- velocity -->
<bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath" value="/WEB-INF/velocity/"/>
</bean>
<bean id="velocityViewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<property name="cache" value="true"/>
<property name="prefix" value=""/>
<property name="suffix" value=".vm"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
测试控制器:
@Controller
@RequestMapping("/doc")
public class DocumentController {
@RequestMapping("/test")
public ModelAndView velocityTest() {
List<String> xmens = new ArrayList<String>();
xmens.add("Professor X");
xmens.add("Cyclops");
xmens.add("Iceman");
xmens.add("Archangel");
xmens.add("Beast");
xmens.add("Phoenix");
Map<String, List<String>> model = new HashMap<String, List<String>>();
model.put("xmens", xmens);
return new ModelAndView("testdoc", model);
}
}
Run Code Online (Sandbox Code Playgroud)
/WEB-INF/velocity/test.vm
<html>
<body>
<ul>
#foreach ($xmen in $xmens)
<li>$xmen</li>
#end
</ul>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我有这样的速度模板:
+-----------------------------------------------------------+-------------+-------------+-------------+-------------+
| $totalPel Pelanggan | $totalBk | $totalAdm | $totalTag | $totalTotal |
+-----------------------------------------------------------+-------------+-------------+-------------+-------------+
Run Code Online (Sandbox Code Playgroud)
当我输入 $totalPel -> 100 时,结果是:
+-----------------------------------------------------------+-------------+-------------+-------------+-------------+
| 100 Pelanggan | $totalBk | $totalAdm | $totalTag | $totalTotal |
+-----------------------------------------------------------+-------------+-------------+-------------+-------------+
Run Code Online (Sandbox Code Playgroud)
其实我想得到这样的结果:
+-----------------------------------------------------------+-------------+-------------+-------------+-------------+
| 100 Pelanggan | $totalBk | $totalAdm | $totalTag | $totalTotal |
+-----------------------------------------------------------+-------------+-------------+-------------+-------------+
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我如何制作它?
我使用这个java代码:
Velocity.init();
VelocityContext context = new VelocityContext();
context.put("totalPel", 100);
Template template = Velocity.getTemplate("LaporanTagihan.txt");
StringWriter writer = new StringWriter();
template.merge(context, writer);
System.out.println(writer.toString());
Run Code Online (Sandbox Code Playgroud) 我不是问如何实现这个,这个概念很简单.我遇到的问题是花车.这是我的代码:
Position += mVelocity;
if (!Keyboard.GetState().IsKeyDown(Keys.Left) && !Keyboard.GetState().IsKeyDown(Keys.Right) && !Keyboard.GetState().IsKeyDown(Keys.Down) && !Keyboard.GetState().IsKeyDown(Keys.Up))
{
if (mVelocity.X != 0.0F)
{
if (mVelocity.X > 0.0F)
mVelocity.X -= mFriction;
if (mVelocity.X < 0.0F)
mVelocity.X += mFriction;
}
if (mVelocity.Y != 0.0F)
{
if (mVelocity.Y > 0.0F)
mVelocity.Y -= mFriction;
if (mVelocity.Y < 0.0F)
mVelocity.Y += mFriction;
}
}
Console.WriteLine(mVelocity.X + ", " + mVelocity.Y);
Run Code Online (Sandbox Code Playgroud)
mFriction是0.2F.
问题是,如果我以正速度(X或Y)移动玩家,摩擦力就会发挥作用,他的速度降低到0.0.但是,如果我以负速度移动他,摩擦会增加,并且出于某种原因,不会停在0.0,而是在停止之前上升到0.2.因此,我有一个移动的玩家,然后当我松开钥匙时,他开始在相反的方向缓慢滑动.为什么是这样?我该如何解决?
另外,我试过这段代码进行测试:
if (mVelocity.X == 0.2F)
mVelocity.X = 0.0F;
if (mVelocity.Y == 0.2F)
mVelocity.Y = 0.0F;
Run Code Online (Sandbox Code Playgroud)
但它给了我完全相同的结果,好像我没有添加代码.显然,0.2F不等于0.2F.这可能是什么?
最后,在调试输出中,当玩家处于静止状态时,他可以正向移动(假设停止)他的x和y的速度(取决于我如何移动他)是2.980232E-08.我不明白这一点.如果我将速度设置为1,并且每帧减去0.2,那为什么它会以1.0,0.8,0.6,0.4,0.2,0.0之外的其他方式去除?接下来,如果他因为负面移动而处于休息状态,他对x和y的速度(再次,取决于我如何移动他)是0.2.为什么它不会变为-1,-0.8,-0.6,-0.4,-0.2,0.0?而不是从0.0到0.2超过.
这一切对我来说毫无意义,如果有人能为我清楚这一点,我将不胜感激.任何替代解决方案也被接受.如果需要更多代码或澄清,我很乐意提供.
的$pod.id
和$SplitMap.get("$pod.id")
不为空。
这个循环也有效:
#set($start = 0)
#set($end = 1)
Run Code Online (Sandbox Code Playgroud)
但这不起作用:
#set($start = 0)
#set($end = $Integer.parseInt($SplitMap.get("$pod.id")))
Run Code Online (Sandbox Code Playgroud)
它给出了异常:
#set($start = 0)
#set($end = $Integer.parseInt("$SplitMap.get("$pod.id"))")
Run Code Online (Sandbox Code Playgroud) 我正在尝试获取用户的个人资料图片并将其显示在我的 liferay 主题中。到目前为止,我已经能够User
通过速度$user
变量访问对象。用户模型有一个被调用的方法getPortraitUrl()
,该方法将其ThemeDisplay
作为参数。我在 liferay 文档中读到,在themeDisplay
使用主题时,该对象在运行时可用,但我似乎无法做到这一点。
我尝试了几种不同的方法来获取themeDisplay
对象,但它们似乎都不起作用:
$theme
$themeDisplay
$request.get("theme-display")
$theme_display
... 以及其他几种不返回任何内容的方法。
$user.getPortraitUrl($themeDisplay)
是我正在努力实现的目标。
任何帮助将不胜感激
我需要在Atlassian Confluence中编写一些用户宏.它使用Apache Velocity模板引擎.如何在该上下文中找到可用的API?
例如,一个社区提供的宏使用像$spaceManager
.如何枚举所有可用的对象,并获取其方法的文档?
在对Atlassian的网站页面上列出的对象是不完整的:它不仅只列出可用的真实对象的一小部分,这也是不特定的用户宏观背景下,甚至我的汇合特定版本.(例如,用户宏被赋予与其他插件点中使用的Velocity不同的Velocity上下文,并且具有不同的可用对象,Confluence 5.1中可用的对象与Confluence 5.6中提供的对象不同.)
Atlassian Answers网站上有类似的问题,但没有一点指向完整的API和类型引用.
我在我的项目中使用 Joda Money.class 作为货币。
我正在使用 NumberTool 来格式化 Velocity 模板中的数字。
context.put("number", new NumberTool());
Run Code Online (Sandbox Code Playgroud)
我将 Money 值转换为 int 以将这些值放置在 Velocity 模板中。
例子:
// 123435 €1234.35
priceInCents = price.getAmountMinorInt();
Run Code Online (Sandbox Code Playgroud)
我想在 Velocity 模板中格式化这个值,如下所示:
1.234,35
Run Code Online (Sandbox Code Playgroud)
我该如何实现?
我尝试了以下情况:
$number.format('#0,00', $price) //Output: 1234,35
$number.format('#0.00', $price) //Output: 123435.00
$number.format('#00,00', $price) //Output: 12,34,35
$number.format('#00.00', $price) //Output: 123435.00
$number.format('#000,00', $price) //Output: 12,34,35
$number.format('#000.00', $price) //Output: 123435.00
Run Code Online (Sandbox Code Playgroud) 我需要一种直接的方法来使用速度模板和 JSON 字符串数据来生成 HTML 数据。例如:
String mergedHtml = Velocity.someMethodToParseTemplate("VelocityTemplate.vm" ,String JsonString");
如何做呢 ?请建议“someMethodToParseTemplate”的代码?
我应该在以下foreach循环中添加什么(速度代码),以获得最终的结果,如appNames = A,B,C
#if($approval.has())
#foreach($item in $approval.rejected)
#set($appNames =$item.appName)
#end
#end
Run Code Online (Sandbox Code Playgroud)
谢谢
velocity ×10
java ×5
apache-fop ×1
c# ×1
confluence ×1
formatting ×1
freemarker ×1
json ×1
liferay ×1
liferay-6 ×1
spring-mvc ×1
xna ×1