2016-12-05 124 views
0

我有一個這樣的枚舉:如何在百里香葉中顯示枚舉getter值?

public enum UnitTypes { 

LITER("l"), KILO("kg"), PIECE("pc"); 

private String unitType; 

UnitTypes(String type) { 
    this.unitType = unitType; 
} 

String getType() { 
    return unitType; 
} 

}

如何顯示從上視圖getType方法的單個值?

我嘗試這一點,但它不工作:

<td th:text="${stock.unit.getType()}"></td> 

在 「股票」 我有場,這是該枚舉類型( 「單位」)

+0

你有什麼是正確的(你甚至可以把'$ {stock.unit.type}'縮短它)。你得到的錯誤是什麼? – Metroids

+0

@Metroids好吧,我已將getType()更改爲公共方法。現在,我沒有錯誤,但只是一個空白字段(使用此顯示什麼) – wegtis

回答

0
UnitTypes(String type) { 
    this.unitType = unitType; 
} 

此代碼應是

UnitTypes(String type) { 
    this.unitType = type; 
} 

您正在爲您的原始代碼分配unitType自身。

+0

是,這樣一個愚蠢的錯誤。謝謝 – wegtis

相關問題