iterating over Enum constants in JSP

后端 未结 2 1485
长情又很酷
长情又很酷 2021-01-04 03:52

I have an Enum like this

package com.example;

public enum CoverageEnum {

    COUNTRY,
    REGIONAL,
    COUNTY
}

I would like to iterate

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-04 04:34

    If you're using Spring MVC, you can accomplish your goal with the following syntactic blessing:

     
       Cluster Type
          
       
       
     
    

    where your model attribute (ie, bean/data entity to populate) is named cluster and you have already populated the model with an enum array of values named clusterTypes. The part is very much optional.

    In Spring MVC land, you can also auto-populate clusterTypes into your model like this

    @ModelAttribute("clusterTypes")
    public MyClusterType[] populateClusterTypes() {
        return MyClusterType.values();
    }
    

提交回复
热议问题