int与long类型之间的转换 himg = himgDao.findUniqueBy("houseId", entity.getId());如上代码我的houseId为int型,我的entity.getId()为long行,这样我每次运行的时候都说类型错误,如何转换?如何写呢?在线等,说对的分全送~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 himg = himgDao.findUniqueBy("houseId", entity.getId()); 改为himg = himgDao.findUniqueBy(houseId, entity.getId()); 1、调整houseId为long型,如果这个是你在程序中定义的属性,感觉这种方法应该较好,扩大了不会丢失数据2、entity.getId()进行强制转换成int,但是可能会产生精度丢失! himg = himgDao.findUniqueBy("houseId", (int)entity.getId()); 你的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型变量会自动转换 1楼的不行,4楼的提示 cannot cast long to int! himg = himgDao.findUniqueBy("houseId", entity.getId()); ------------------------------------我都不知道你什么意思了?是把entity.getId()改为int型吗?那就那样himg = himgDao.findUniqueBy("houseId", new Interger(entity.getId())); himg = himgDao.findUniqueBy("houseId", new Interger(entity.getId())); 修正himg = himgDao.findUniqueBy("houseId", new Integer(entity.getId())); int pre, suffix; pre=(entity.getId()> > 16)&0xffff; //取高字节 suffix=entity.getId()&0xffff; //取低字节 那还不如改成long型himg = himgDao.findUniqueBy(new Long(houseId), entity.getId()); 楼主是想把himg = himgDao.findUniqueBy("houseId", entity.getId()); 中的entity.getId()转化为int型吗?如果是的话试试himg = himgDao.findUniqueBy("houseId", Integer.parseInt(String.valueOf(entity.getId())))可以不 jsp页面许多标签报错 java mail怎样查找指定邮件? 谁给我来一个简单的模糊查询的例子谢谢 oracle 哪位高手可以给小妹指点一下,先谢啦! 视频问题!在线等~ 大菜鸟提问题,有关横向显示数据 新开一贴继续求sqlserver7 jdbc驱动 求能下载tomcat4.1的国内网站, 紧急求救,关于jsp中的javascript 关于第三方支付接口问题 tomcat怎么配置hibernate项目 JDBC连接数据库 ResultSet.updataRow();是什么意思?
himg = himgDao.findUniqueBy(houseId, entity.getId());
2、entity.getId()进行强制转换成int,但是可能会产生精度丢失!
int i1 = 10; //定义一个int型变量
long l1 = 10L;//定义一个long型变量
int i2 = (int)l;//通过强制转换把一个long型的变量转换成一个int型变量
//int i2 = l;这样会出编译错误
long l2 = i1;//int型变量会自动转换
4楼的提示 cannot cast long to int!
------------------------------------
我都不知道你什么意思了?是把entity.getId()改为int型吗?
那就那样
himg = himgDao.findUniqueBy("houseId", new Interger(entity.getId()));
修正
himg = himgDao.findUniqueBy("houseId", new Integer(entity.getId()));
pre=(entity.getId()> > 16)&0xffff; //取高字节
suffix=entity.getId()&0xffff; //取低字节
himg = himgDao.findUniqueBy(new Long(houseId), entity.getId());