Java:动态应用 Velocity 脚本
我正在使用 Struts MVC 构建一个小 portlet,用于从 Web 服务搜索/列出书籍。
在我的第一次测试中,我将 Velocity Tools 集成到我的 Struts 项目中,没有出现任何问题。
最后一步是允许用户选择是否要使用速度。如果是,速度脚本将以字符串形式来自 Web 服务。 我将测试放在 JSP 页面中,以便可以应用以下算法:
List<Book> books = myWebservice.getAllBooks();
if (user.preference.vm = enabled ){
String velocityScript = myWebservice.getARandomVelocityScript()
renderTheBooks(velocityScript,books);
}
else{
use JSP and/or struts tags to generate the content
}
问题出在 renderTheBooks(velocityScript,books)
行:我该如何编码?
谢谢,问候。
(我知道该架构可能看起来有点奇怪,但是请让我们讨论一下 renderTheBooks 方法。我将不胜感激您理解这一点。)
I'm building a little portlet with Struts MVC that searches/lists books from a webservice.
In my very first tests, I integrated the Velocity Tools in my Struts project with no problem.
The final step is to allow the user to choose if he wants to use velocity or not. If yes, the velocity script will come from a webservice as a String.
I put the test in a JSP page so that I can apply the following algorithm :
List<Book> books = myWebservice.getAllBooks();
if (user.preference.vm = enabled ){
String velocityScript = myWebservice.getARandomVelocityScript()
renderTheBooks(velocityScript,books);
}
else{
use JSP and/or struts tags to generate the content
}
The problem is at the renderTheBooks(velocityScript,books)
line : How can I code it?
Thank you, regards.
(I know that the architecture can seem a little bit odd but please, let us discuss the renderTheBooks
method rather. I will appreciate you understand that point.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Velocity 类为您提供静态便捷方法:
假设阅读器包含您的速度模板,并且速度配置正确
您可以使用此方法对其进行评估
Velocity class offers you static convenience method:
Assuming that reader contains your velocity template, and velocity was configured correctly
you can evaluate it using this method
这样您就可以快速渲染书籍列表。
This way you can render list of books in velocity.