代码之家  ›  专栏  ›  技术社区  ›  robert trudel

Spring mvc无法接收一组字符串

  •  0
  • robert trudel  · 技术社区  · 7 年前

    冬眠

    我有一个实体:工厂

    @Entity
    public class Factories extends BaseEntity {
    
        @Id
        @SequenceGenerator(name = "factories_id_seq", sequenceName = "factories_id_seq", allocationSize = 1)
        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "factories_id_seq")
        private Integer id;
    
    
        @ElementCollection
        private Set<String> emails = new HashSet<String>();
    
        //get set...
    }
    

    在百里香为工厂添加电子邮件,

     <table id="emailsTable" class="table table-striped table-hover responsive">
          <thead>
              <tr>
                  <th th:text="#{value}">Value</th>
                  <th></th>
              </tr>
          </thead>
          <tbody>
              <tr th:each="email, stat : *{emails}">
                  <td><input type="text" class="form-control" th:placeholder="#{email.placeholder}" placeholder="Name" th:field="*{emails[__${stat.index}__]}" /></td>
                  <td class="align-middle"><button type="button" class="btn btn-default pull-right delete"><i class="fas fa-trash-alt"></i></button></td>
              </tr>
          </tbody>
    </table>
    

    当我试图拯救,我得到

    org.springframework.beans.InvalidPropertyException:属性无效 bean类[com.lcm.model.Factories]的'emails[0]:属性 索引属性路径“emails[0]中引用的既不是数组 不是列表也不是映射;返回值是[[]]

    1 回复  |  直到 7 年前
        1
  •  1
  •   Marc Collin    7 年前

    这是不可能的,因为集合没有顺序…检查这篇文章有几个选择。。。

    Need help with binding Set with Spring MVC form