我有一个与弹簧形式控制器关联的命令对象:public class PluginInstance { private Set<PluginParameter> pluginParameters = new HashSet<PluginParameter>(); ... some other string/long properties and getter setters...}PluginParameter也有一个Set,其中包含值public class PluginParameter { private String parmName; private Set<PluginParmvalue> pluginParmvalues = new HashSet<PluginParmvalue>(); ...some other string/long properties and getter setters...}(通常,pluginParmvalues仅包含一个值,已使用列表进行将来的扩展)在春季形式中,我将值绑定为<form:input path="pluginParameters[${itemsRow.index}].pluginParmvalues[0].parmValue" />但问题是可以有一个form:select(向用户显示多个预定义选项)或form:input(用户可以输入任何值)。这必须由另一个对象决定public class PluginConfigParm { private String parmName; private ArrayList<String> choices; ...getter setters and other properties}当它们匹配并且PluginConfigParm.choices.size()> 0时,我必须将PluginConfigParm.paramName的名称与PluginParameter.paramName进行比较,然后form:select将显示为PluginConfigParm.choices的值填充,否则form:input将显示。问题很简单:我该怎么做。任何帮助将不胜感激。 最佳答案 通过在控制器中使用List 而不是Set 。问题解决了。可能是Set 没有可以与spring形式绑定的getter / setter。所以<form:input path="pluginParameters[${itemsRow.index}].pluginParmvalues[0].parmValue" />控制器中的List 使我的生活更轻松。
09-11 17:18