How do I bind collection attributes to a form in Spring MVC

后端 未结 6 981
忘了有多久
忘了有多久 2021-02-04 05:17

I\'m trying to bind one of my model objects to the fields of a form, using Spring-MVC. Everything works fine, except that one of the attributes of the model object is an unorder

6条回答
  •  独厮守ぢ
    2021-02-04 05:58

    I think the reason that it doesn't work with a Set is because a the order of a Set is not guaranteed. When you try to bind to the first object on post, it may not have been the first object in that list to render out. For example, items[0] may not be the same between the GET and the POST.

    So it should work fine if you use an implementation of Set that is ordered, such as a SortedSet or TreeSet.

提交回复
热议问题