2012-09-27 32 views
0

我在下面的循环中获取数据时遇到问题,即使大小不为零,我在sysout'data is'中得到空值。哪里出错?循环中的问题获取值

List<Long> dd = domainItemMapper.getIsSearchable(34372); 
    System.out.println("the test is-" + dd.size()); 
    for (int i = 0; i < dd.size(); i++) { 
     Long isSearch = dd.get(i); 
     System.out.println("data is"+dd.get(i)); 
     if (isSearch.equals(0)) { 
      isSearchValue = false; 
     } else 
      isSearchValue = true; 
    } 

数据库的调用是一个MyBatis的通话如下 接口

List<Long> getIsSearchable(@Param("parentFieldId") long parentFieldId); 

IMPL

<mapper namespace="com.ge.dbt.common.persistence.IFormValidatorMapper"> 

     <select id="getIsSearchable" statementType="CALLABLE" 
     resultType="Long"> 
     select is_searchable from t_field where parent_field_id=#{parentFieldId} 
    </select> 

</mapper> 
+6

带有空记录的列表。 – Nishant

+1

请提供一些'domainItemMapper.getIsSearchable(34372)' –

+1

'List '代码允许包含'null'元素。显然'getIsSearchable'返回这样一个列表。 – Dims

回答

0

我猜你的整个代码可以被转换成两行。在Java中的Long

if(dd!= null && !dd.isEmpty()) 
return dd.contains(0);//Contains Guard you in such cases because equals check 
         //happen on passed element ie *0* 

默认值为null。所以你需要在你的情况下额外检查null

0

附上您的isSearch.equals支票在支票null

if(isSearch != null) 
{ 
    if (isSearch.equals(0)) 
    {    
     isSearchValue = false;   
    } 
    else    
    { 
     isSearchValue = true; 
    } 
} 

但是它会更好地修改代码domainItemMapper.getIsSearchable(34372);方法,以便它不与null填充列表都没有。

0

似乎是你的列表包含null文字。并且List支持null作为值。

0

根据您的这条评论

数据已空,0和1 data.I只想为0和1

你需要修复您这样的查询返回数据

select is_searchable from t_field where parent_field_id=#{parentFieldId} and is_searchable is not NULL;