How to insert a value into Set collection in Struts 2(如何在 Struts 2 中将值插入 Set 集合)
问题描述
我正在使用 Struts2 做一个项目,但在分配集合时遇到问题.
I am doing a project using Struts2 and I have a problem assigning a set collection.
这是我的操作(我删除了不相关的部分)
Here's my Action (I eliminated the irrelevant part)
这是我的模型Team
(我去掉了不相关的部分)
Here's my model Team
(I eliminated the irrelevant part)
这是我的 JSP 部分
Here's my JSP part
现在的问题是我无法通过 ModelDriven
将正确的值插入到这个 Set
集合中,它会抛出异常.你能告诉我在 JSP 文件中写什么,以便我可以在我的模型中向 Set
集合插入一个值吗?
Now the problem is I can't insert the right value into this Set
collection in by ModelDriven
, it will throw a exception. Could you please tell me what to write in JSP file, so I can insert a value to Set
collection in my model?
推荐答案
Set
是一个 Collection
并且任何其他集合都可以通过属性进行索引.
Set
is a Collection
and as any other collection could be indexed by a property.
在 JSP 中
有关此的更多信息,请参阅
More about this see
按集合的属性索引集合.
也有可能获得一个独特的元素通过传递给定属性的值来收集那个元素.默认情况下,属性集合的元素在<Class>->conversion.properties
使用KeyProperty_xxx=yyy
,其中 xxx
是属性返回集合的 bean Class
和yyy
是集合元素的属性我们要索引.
It is also possible to obtain a unique element of a collection by passing the value of a given property of that element. By default, the property of the element of the collection is determined in
<Class>->conversion.properties
usingKeyProperty_xxx=yyy
, wherexxx
is the property of the beanClass
that returns the collection andyyy
is the property of the collection element that we want to index on.
这篇关于如何在 Struts 2 中将值插入 Set 集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!