Convert integer value to string using JSTL/EL

前端 未结 4 1727
独厮守ぢ
独厮守ぢ 2020-12-18 19:09

How do I correct this statement:

${model.myHashtable[model.data.id]}.

myHashtable is defined as

Hashtable

        
相关标签:
4条回答
  • 2020-12-18 19:41

    ${''.concat(model.data.id)} works for me,you may try it.

    0 讨论(0)
  • 2020-12-18 19:45

    Set it as body of <c:set>. It will implicitly be converted to String.

    <c:set var="idAsString">${model.data.id}</c:set>
    <c:out value="${model.myHashtable[idAsString]}" />
    
    0 讨论(0)
  • 2020-12-18 19:48

    you can use org.apache.commons.collections4.map.CaseInsensitiveMap both String "1" and int 1 are the same key;

    0 讨论(0)
  • 2020-12-18 19:48

    In JSP file:

    <%@ taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt" %>
    
    <!-- lines of code... -->
    
    <fmt:parseNumber var = "id_value" type = "number" value = "${model.data.id}" />
    <c:out value = "${id_value}" />
    
    0 讨论(0)
提交回复
热议问题