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

后端 未结 6 990
忘了有多久
忘了有多久 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:57

    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] Indicates the third element of the indexed property account. Indexed properties can be of type array, list or other naturally ordered collection (emphasis theirs)

    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.

提交回复
热议问题