Access Enum value using EL with JSTL

前端 未结 13 1977
迷失自我
迷失自我 2020-11-29 00:18

I have an Enum called Status defined as such:

public enum Status { 

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

    private final String val;

    Status(String va         


        
13条回答
  •  Happy的楠姐
    2020-11-29 00:42

    <%@ page import="com.example.Status" %>
    
    1. ${dp.status eq Title.VALID.getStatus()}
    2. ${dp.status eq Title.VALID}
    3. ${dp.status eq Title.VALID.toString()}
    
    • Put the import at the top, in JSP page header
    • If you want to work with getStatus method, use #1
    • If you want to work with the enum element itself, use either #2 or #3
    • You can use == instead of eq

提交回复
热议问题