1. 程式人生 > >el表示式中判斷無效

el表示式中判斷無效

今天發現個問題:el表示式中<c:if>判斷無效
el表示式中<c:if>判斷的問題: 下面的方式根本就無效: 把它當成字串處理: <c:if test="${item.word_source == '0'}">採集</c:if>  
         <c:if test="${item.word_source== '1'}">配置</c:if>
或是
<c:if test="${item.word_source eq '0'}">採集</c:if>  
        <c:if test="${item.word_source eq '1'}">配置</c:if>
換成<c:choose> 表籤 還是不行
把它當做陣列處理:(頁面直接報錯)
<c:if test="${item.word_source == 0}">採集</c:if>  
        <c:if test="${item.word_source == 1}">配置</c:if>
或是
<c:if test="${item.word_source *1 == 0}">採集</c:if>  
        <c:if test="${item.word_source*1  == 1}">配置</c:if>
可是 ${item.word_source} 可以取到值 0 或是1 可是比較時出錯。
然後我去檢視資料庫中  word_source 發現其型別是char(2),情況和上面介紹的 都是因為是char型別轉化的時候出錯導致的。
可是把資料庫中的欄位型別改成varchar,我只是個小小的程式設計師,這個我改不了呀。命苦呀,知道問題所在,也知道怎麼改正,可是發現自己沒有許可權。
因為我的沒有實體類,直接從jdbctemplate查詢出list列表,不能對類的屬性直接進行強制轉換成String型別。
想找其他方法看看能不能避開修改資料庫欄位型別,發現我還是嫩了點,真為自己的智商抓急呀。 只能問問同事:
sql查詢語句:
select t.*,to_char(word_source) as wordSource from table_name t  //這樣測試不行 select t.*,to_number(word_source) as wordSource from table_namet //這樣測試成功
jsp頁面: <c:if test="${item.wordSource== 0}">採集</c:if>  
        <c:if test="${item.wordSource== 1}">配置</c:if>
實在不行的話: 你可以對 jdbcTemplate查詢出的list進行處理:
 for (Map<String, Object> map : list)     {
//取到該值強制型別後再新增到list中
     String val=(String) list.get(0).get("word_source");
    }