使用 EL 和 JSTL 访问枚举值 [英] Access Enum value using EL with JSTL

查看:33
本文介绍了使用 EL 和 JSTL 访问枚举值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 Status 的 Enum 定义如下:

I have an Enum called Status defined as such:

public enum Status { 

    VALID("valid"), OLD("old");

    private final String val;

    Status(String val) {
        this.val = val;
    }

    public String getStatus() {
        return val;
    }

}

我想从 JSTL 标记访问 VALID 的值.特别是 标签的 test 属性.例如

I would like to access the value of VALID from a JSTL tag. Specifically the test attribute of the <c:when> tag. E.g.

<c:when test="${dp.status eq Status.VALID">

我不确定这是否可行.

推荐答案

与字符串的简单比较有效:

A simple comparison against string works:

<c:when test="${someModel.status == 'OLD'}">

这篇关于使用 EL 和 JSTL 访问枚举值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆