簡體   English   中英

如何使用在html頁面中創建的枚舉類

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

我有一個名為“ BlankEnm”的枚舉類,並且有一個searchlayout.html頁面。 如何在<select><option> )標記的html頁面中使用枚舉velues。 我想在選擇框(組合框)中看到它們

我嘗試過對th標簽( <th th:text="bla bla "> )進行操作,但沒有任何進展。 沒用

這是我想在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;
}

}

我希望在選擇框中的html頁面中使用我的枚舉類元素

我建議您將Enum的值存儲在一個新類中,而不是遍歷一個ArrayList,其中包含您的類的不同對象。

你的班:

public class Data {

private int id;
...

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

}

數組列表:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM