在 class EnumDefine中有这么一个枚举
public enum GoodsType {
GOODS_TYPE_OTHER(0, "other"), //其他
GOODS_TYPE_GENERAL(1, "general"), //普通商品
GOODS_TYPE_TASK(2, "task"), //任务商品
GOODS_TYPE_COUPON(3, "coupon"), //全抵商品
GOODS_TYPE_DISCOUNT(4, "discount"); //折扣商品
private Integer code;
private String msg;
GoodsType(Integer code, String msg) {
this.code = code;
this.msg = msg;
}
public Integer getCode() {
return code;
}
public String getMsg() {
return msg;
}
/**
* 根据枚举的code返回枚举对象
*
* @param code 枚举code值
* @return 枚举对象
*/
public static GoodsType getEnumByCode(Integer code) {
if (code == null) return null;
for (GoodsType status : values()) {
if (status.getCode() == code)
return status;
}
return null;
}
}我在config中去添加共享方法
public void configEngine(Engine me) {
me.addSharedMethod(new EnumDefine());
}前端html中去调用
<option value="#(type)">
#if(type == GoodsType.GOODS_TYPE_GENERAL.getCode())
#(message("Goods.Type." + GoodsType.GOODS_TYPE_GENERAL.getMsg()))
#end
</option>报错
com.jfinal.template.TemplateException: "GoodsType" can not be null for accessed by "GoodsType.GOODS_TYPE_GENERAL"
模板支持这么去调用枚举吗?
项目:JFinal
public Integer getCode()
public String getMsg()
public static GoodsType getEnumByCode(Integer code)
而 GoodsType.GOODS_TYPE_GENERAL.getMsg() 这个与 shared method 完全无关了