更新时间:2023-10-05 19:06:58
我认为它必须是一个有序的集合。例如,Spring参考中有图表讨论如何引用属性。它说:
I think it has to be an ordered collection. For example,there's a chart in the Spring reference that talks about how to reference properties. It says:
account [2]表示索引属性帐户的第三个元素
。
索引属性的类型可以是
数组,列表或其他自然排序的
集合(强调他们的)
account[2] Indicates the third element of the indexed property account. Indexed properties can be of type array, list or other naturally ordered collection (emphasis theirs)
也许一种方法是向对象添加一个getter,而不是返回你的Set,返回Set.toArray()。然后您的items属性将引用该数组。当然,你不能依赖订购。
Perhaps one approach would be to add a getter to your object that, rather than returning your Set, returns Set.toArray(). Then your items attribute would reference the array. Of course, you can't depend on the ordering.