• <i id='mtZY2'><tr id='mtZY2'><dt id='mtZY2'><q id='mtZY2'><span id='mtZY2'><b id='mtZY2'><form id='mtZY2'><ins id='mtZY2'></ins><ul id='mtZY2'></ul><sub id='mtZY2'></sub></form><legend id='mtZY2'></legend><bdo id='mtZY2'><pre id='mtZY2'><center id='mtZY2'></center></pre></bdo></b><th id='mtZY2'></th></span></q></dt></tr></i><div id='mtZY2'><tfoot id='mtZY2'></tfoot><dl id='mtZY2'><fieldset id='mtZY2'></fieldset></dl></div>

          <bdo id='mtZY2'></bdo><ul id='mtZY2'></ul>
      1. <legend id='mtZY2'><style id='mtZY2'><dir id='mtZY2'><q id='mtZY2'></q></dir></style></legend>

        <small id='mtZY2'></small><noframes id='mtZY2'>

        <tfoot id='mtZY2'></tfoot>

        如何在 Struts 2 中将值插入 Set 集合

        时间:2023-07-27

        • <small id='NQmbe'></small><noframes id='NQmbe'>

                <tbody id='NQmbe'></tbody>

              • <bdo id='NQmbe'></bdo><ul id='NQmbe'></ul>
                <legend id='NQmbe'><style id='NQmbe'><dir id='NQmbe'><q id='NQmbe'></q></dir></style></legend>

                <i id='NQmbe'><tr id='NQmbe'><dt id='NQmbe'><q id='NQmbe'><span id='NQmbe'><b id='NQmbe'><form id='NQmbe'><ins id='NQmbe'></ins><ul id='NQmbe'></ul><sub id='NQmbe'></sub></form><legend id='NQmbe'></legend><bdo id='NQmbe'><pre id='NQmbe'><center id='NQmbe'></center></pre></bdo></b><th id='NQmbe'></th></span></q></dt></tr></i><div id='NQmbe'><tfoot id='NQmbe'></tfoot><dl id='NQmbe'><fieldset id='NQmbe'></fieldset></dl></div>
                <tfoot id='NQmbe'></tfoot>
                  本文介绍了如何在 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)

                  public class TeamAction extends BaseAction implements ModelDriven<Team>
                  {
                   Team team=new Team();
                  
                  }
                  

                  这是我的模型Team(我去掉了不相关的部分)

                  Here's my model Team (I eliminated the irrelevant part)

                  private TeamId id;
                  private Set students = new HashSet(0);
                  

                  这是我的 JSP 部分

                  Here's my JSP part

                  <input type="text" name=team.student[0].id />
                  

                  现在的问题是我无法通过 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.

                  @Element(value = Student.class)
                  @Key(value = Integer.class)
                  @KeyProperty(value = "id") 
                  @CreateIfNull(value = true)
                  private Set<Student> students = new HashSet(0);
                  //getter and setter, also for Student class that should have Integer id.
                  

                  在 JSP 中

                  <s:iterator value="students " var="student">
                    <s:textfield name="students(%{#student.id}).name" />
                  </s:iterator>
                  


                  有关此的更多信息,请参阅


                  More about this see

                  按集合的属性索引集合.

                  也有可能获得一个独特的元素通过传递给定属性的值来收集那个元素.默认情况下,属性集合的元素在<Class>->conversion.properties 使用KeyProperty_xxx=yyy,其中 xxx 是属性返回集合的 bean Classyyy 是集合元素的属性我们要索引.

                  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 using KeyProperty_xxx=yyy, where xxx is the property of the bean Class that returns the collection and yyy is the property of the collection element that we want to index on.

                  这篇关于如何在 Struts 2 中将值插入 Set 集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在不强制转换的情况下将 double 转换为 long 下一篇:如何将长转换/转换为字符串?

                  相关文章

                  最新文章

                  <i id='aTgIp'><tr id='aTgIp'><dt id='aTgIp'><q id='aTgIp'><span id='aTgIp'><b id='aTgIp'><form id='aTgIp'><ins id='aTgIp'></ins><ul id='aTgIp'></ul><sub id='aTgIp'></sub></form><legend id='aTgIp'></legend><bdo id='aTgIp'><pre id='aTgIp'><center id='aTgIp'></center></pre></bdo></b><th id='aTgIp'></th></span></q></dt></tr></i><div id='aTgIp'><tfoot id='aTgIp'></tfoot><dl id='aTgIp'><fieldset id='aTgIp'></fieldset></dl></div>
                • <tfoot id='aTgIp'></tfoot>
                  • <bdo id='aTgIp'></bdo><ul id='aTgIp'></ul>

                  <small id='aTgIp'></small><noframes id='aTgIp'>

                • <legend id='aTgIp'><style id='aTgIp'><dir id='aTgIp'><q id='aTgIp'></q></dir></style></legend>