今天发现个问题: 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 可是比较时出错。
网上大多数都是围绕这边博文来讲: http://baomw.iteye.com/blog/177373
然后我去查看数据库中 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_name t //这样测试成功
<c:if test="${item. wordSource == 1}">配置</c:if>
jsp页面:<c:if test="${item.wordSource == 0}">采集</c:if>
实在不行的话:你可以对 jdbcTemplate查询出的list进行处理:
for (Map<String, Object> map : list){
//取到该值强制类型后再添加到list中
String val=(String) list.get(0).get("word_source");
}