简体   繁体   English

如何使用在html页面中创建的枚举类

[英]How can I use an enum class that I created in an html page

I have an enum class named "BlankEnm" and have a searchlayout.html page. 我有一个名为“ BlankEnm”的枚举类,并且有一个searchlayout.html页面。 How can i use enum velues in html page in <select> ( <option> ) tags. 如何在<select><option> )标记的html页面中使用枚举velues。 i want to see them in the select box (combo box) 我想在选择框(组合框)中看到它们

I tried obuot the th tags ( <th th:text="bla bla "> ), but coudn't get any progress. 我尝试过对th标签( <th th:text="bla bla "> )进行操作,但没有任何进展。 It didn't work. 没用

here is my enum class that i would like to use in the html page; 这是我想在html页面中使用的我的枚举类;

public enum BlankEnm {
ALL(0,"blankEnm.all"),
TITLE(1, "blankEnm.title"),
IDENTITY(2, "blankEnm.identity"),
TAXNUMBER(3, "blankEnm.taxNumber");


private final int id;
private final String text;

BlankEnm(int id, String text) {
    this.id = id;
    this.text = text;
}

public int id() {
    return this.id;
}

public String text() {
    return this.text;
}


public static int blankMapper(String blankChar) {
    switch (blankChar.toLowerCase()) {
        case "ü":
            return TITLE.id;
        case "k":
            return IDENTITY.id;
        case "v":
            return TAXNUMBER.id;
        default:
            return 0;
    }
}


public static BlankEnm parseType(Integer value) {
    for (BlankEnm type : BlankEnm.values()) {
        if (value.equals(type.id())) {
            return type;
        }
    }
    return null;
}

}

I expect using my enum class elements in the html page in a select box 我希望在选择框中的html页面中使用我的枚举类元素

I'd suggest you to store the values of your Enum in a new class and than iterate throug an ArrayList with the different objects of your class in it. 我建议您将Enum的值存储在一个新类中,而不是遍历一个ArrayList,其中包含您的类的不同对象。

Your Class: 你的班:

public class Data {

private int id;
...

public Data(int id) {
this.id = id;
...
}

}

Array List: 数组列表:

ArrayList<Data> list = new ArrayList<>();
list.add(new Data(0));
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM