使用Freemarker中的参数调用Java方法 [英] Invoke Java method with parameters from Freemarker

查看:74
本文介绍了使用Freemarker中的参数调用Java方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下FTL标记对我来说很好用,并在我的服务器端JiveActionSupport对象中调用getWidgets():

The following FTL markup works fine for me and calls getWidgets() in my server-side JiveActionSupport object:

<#list widgets! as widget>
  -- do something with widget.sku
</#list>

但是,我确实需要一个依赖于小部件属性的内部列表,如下所示:

However, I really need an inner list that depends on a property of widget, something like this:

<#list widgets! as widget>
  <#list manufacturers(widget.sku)! as manufacturer>
  -- do something with manufacturer
  </#list>
</#list>

我尝试实现服务器端代码,如下所示:

I have tried to implement the server-side code, as either:

public List<Manufacturer> getManufacturers(int sku);
public List<Manufacturer> getManufacturers(String sku);

但是这两个结果都导致表达式制造商在第123行中未定义".

But both result in 'Expression manufacturers is undefined at line 123'.

如何将参数传递给当前JiveActionSupport对象的方法?谢谢.

How can you pass parameters to methods of the current JiveActionSupport object? Thanks.

推荐答案

在这里可能使您感到困惑的是getFoo()可以称为foo,而getFoo(param)不能称为foo(param) ,仅作为getFoo(param).但这就是JavaBeans的工作方式. getFoo()定义了JavaBean属性,而getFoo(params)则没有.

The thing that possibly confused you here is that getFoo() can be called as foo, but getFoo(param) can't be called as foo(param), only as getFoo(param). But this is just how JavaBeans work; getFoo() defines a JavaBean property, while getFoo(params) doesn't.

无论如何,如果getManufacturers是数据模型(根)对象的方法,则(假设适当的对象包装)您应该能够将其称为getManufacturers(param).原则上您不需要以action.开头.

Anyway, if getManufacturers is the method of the data-model (root) object, then (assuming proper object wrapping) you should be able to call it as getManufacturers(param). You don't need to start it with action. in principle.

这篇关于使用Freemarker中的参数调用Java方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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