[英]How to display enum getter value on view in thymeleaf?
I have an enum like this: 我有一个这样的枚举:
public enum UnitTypes {
LITER("l"), KILO("kg"), PIECE("pc");
private String unitType;
UnitTypes(String type) {
this.unitType = unitType;
}
String getType() {
return unitType;
}
} }
How to display a single value from the getType method on view? 如何在视图上显示getType方法中的单个值?
I try this, but it doesn't work: 我尝试了这个,但是不起作用:
<td th:text="${stock.unit.getType()}"></td>
In "stock" i have field, which is this enum type("unit") 在“股票”中,我有一个字段,这是此枚举类型(“单位”)
UnitTypes(String type) {
this.unitType = unitType;
}
This code should be 该代码应为
UnitTypes(String type) {
this.unitType = type;
}
You are assigning unitType to itself, in your original code. 您在原始代码中为其分配unitType。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.