himg = himgDao.findUniqueBy("houseId", entity.getId());如上代码我的houseId为int型,我的entity.getId()为long行,这样我每次运行的时候都说类型错误,如何转换?如何写呢?
在线等,说对的分全送~

解决方案 »

  1.   

    himg = himgDao.findUniqueBy("houseId", entity.getId()); 改为
    himg = himgDao.findUniqueBy(houseId, entity.getId()); 
      

  2.   

    1、调整houseId为long型,如果这个是你在程序中定义的属性,感觉这种方法应该较好,扩大了不会丢失数据
    2、entity.getId()进行强制转换成int,但是可能会产生精度丢失!
      

  3.   

    himg = himgDao.findUniqueBy("houseId", (int)entity.getId()); 
      

  4.   

    你的findUniqueBy方法应该是定义成findUniqueBy(Int,long)吧,你怎么把字符串传进去了,或许我误会了,继续回答你的问题,long和int的相互转换如下:
     int   i1   =   10;     //定义一个int型变量   
      long   l1   =   10L;//定义一个long型变量   
      int   i2   =   (int)l;//通过强制转换把一个long型的变量转换成一个int型变量   
      //int   i2   =   l;这样会出编译错误   
      long   l2   =   i1;//int型变量会自动转换
      

  5.   

    1楼的不行,
    4楼的提示 cannot cast long to int!
      

  6.   

    himg = himgDao.findUniqueBy("houseId", entity.getId()); 
    ------------------------------------
    我都不知道你什么意思了?是把entity.getId()改为int型吗?
    那就那样
    himg = himgDao.findUniqueBy("houseId", new Interger(entity.getId()));
      

  7.   

    himg = himgDao.findUniqueBy("houseId", new Interger(entity.getId())); 
    修正
    himg = himgDao.findUniqueBy("houseId", new Integer(entity.getId())); 
      

  8.   

    int   pre,   suffix; 
    pre=(entity.getId()> > 16)&0xffff;               //取高字节 
    suffix=entity.getId()&0xffff;                     //取低字节
      

  9.   

    那还不如改成long型
    himg = himgDao.findUniqueBy(new Long(houseId), entity.getId());
      

  10.   

    楼主是想把himg = himgDao.findUniqueBy("houseId", entity.getId()); 中的entity.getId()转化为int型吗?如果是的话试试himg = himgDao.findUniqueBy("houseId", Integer.parseInt(String.valueOf(entity.getId())))可以不