instanceof 判断数据类型

阅读更多
/**
  * 根据名称进行查找
  */
 public List queryListByNameQuery(String nameQuery,Object... values){
  Query query = getSession().getNamedQuery(nameQuery);
  for (int i = 0,len=values.length; i < len; i++) {
   if(values[i] instanceof String){
    query.setString(i, (String)values[i]);
   }else if(values[i] instanceof Integer){
    query.setInteger(i, (Integer)values[i]);
   }else if(values[i] instanceof Long){
    query.setLong(i, (Long)values[i]);
   }else{
    query.setParameter(i, values[i]);
   }
  }
  return query.list();
 }

 

你可能感兴趣的:(instanceof)