Use <form:select> tag with a map

后端 未结 2 1251
误落风尘
误落风尘 2020-12-29 11:42

Is there a way to map the data inside a map to tag? I have a map Map in my code. Is there a way to map the option labels to the St

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-29 12:22

    The tag supports what you want right out of the box, using the items attribute. You can do something like this:

    LinkedHashMap states = new LinkedHashMap();
    states.put(1, "Alabama");
    states.put(2, "Alaska");
    states.put(3, "Arizona");
    states.put(4, "Arkansas");
    states.put(5, "California");
    

    And so on. Then in your form:

    
        
    
    

    That will be rendered to something like:

    
    

提交回复
热议问题