将用户定义的java对象传递给velocity脚本引擎
我正在使用带有 CQ5 的速度模板。我安装的速度脚本引擎可以识别预定义的 CQ 对象。我想知道如何将用户定义的java对象传递给速度脚本引擎。 我尝试了类似的东西: http://groovy.codehaus.org/JSR+223+Scripting+with+Groovy
但它不起作用..请帮我解决这个情况
提前致谢
im using velocity template with CQ5. the velocity scriptengine i ve installed identifies pre-defined CQ objects. i would like to know how to pass user defined java objects to the velocity script engine.
I tried something similar to this:
http://groovy.codehaus.org/JSR+223+Scripting+with+Groovy
but it doesnt work..Kindly help me to solve this situation
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需要使用
VelocityContext
来传递对象参数,例如context.put("name_of_parameter", yourOBject);
在我的示例中
test.temalate
,$person.address
表示调用 person 对象的地址 getter 方法。示例:尝试如下
Person.java
公共类人{
私有字符串名称;
私有字符串地址;
Test.java
test.template
您将得到如下输出。
You just need to use
VelocityContext
to pass object parameter likecontext.put("name_of_parameter", yourOBject);
In my example
test.temalate
,$person.address
mean call address getter method of person object.Example : Try as below
Person.java
public class Person {
private String name;
private String address;
Test.java
test.template
You will get output as below.