select count(t.id)时遇到java.lang.ClassCastException: java.lang.Long

重用以前的分页程序setTotalCount(sql)失败,遇到java.lang.ClassCastException: java.lang.Long异常

 

解决办法:

((Integer) result.get(0)).intValue();

改为:

((Long) result.get(0)).intValue();

 

显然是sql统计语句返回类型改变了,类似问题可以用以下方法查看返回类型:

 

System.out.println("返回类型:"+result.get(0).getClass().getName());

 

 

此外,

由于setTotalCount(sql)里面catch处理只是简单return 0,害我查了好久不知问题出在哪里,建议捕获异常时务必在控制台输出异常提示,简单printStackTrace()都好。

### Error querying database. Cause: java.lang.RuntimeExceeption: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='itemlId', mode=IN, javatype=class java.lang.Lo ### The error may exist in URL [jar:nested:/srm-mdm.jar/!E300T-INF/classes/!/mapper/cux/HcItemReqHeaderMapper.xml] ### The error_may_involve defaultParameterMap ### The error occurred while setting parameters ### SQL: /*org.srm.mdm.cux.infra.mapper.HcItemReqHeaderMapper.ageItemReqHeader_COUNT*/ SELECT count(0) FROM smdm_item_req ir LEFT JOIN smdm_item_req_header irh ON ir.item_req_header_id = irh.iitem_req_header_id LEFT JOIN srm.iam_user iu1 ON iu1.id = irh.created_by LEFT JOIN srm.iam_user iu2 ON iu2id ## Cause: java.lang.RuntimeException: org.apache.ibatis.ttype.TypeException: Could not set parameters for mapping:ParameterMapping{property='itemId', mode=IN, javaType=class java.lang.Long, jdbcType=BIGINT, numericScale=null, resultMapid='nullL', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error seetting non null for parameter #5 with JdbcType BIGINT. Try setting a different JdbcType for this parameteer or a different configuration property. Cause: java.lang.ClassCastException: class java.lang.Stringcannot be cast to class java.lang.Long (java.lang.String and java.lang.Long are in module java.base of loader 'bootstrap.) at org.apache.ibatis.exceptions.ExceptionFactory.wrapExcepotion(ExceptionFactory.java:30) ~[mybatis-3.5.14.jar!/:3.514] at org.apache.ibatis.session.defaults.DefaultSqlSession.seelectlist(DefaultSqlSession.java:156) ~[mybatis-3.5.14.jar!/:3.5.14] at org.apache.ibatis.session.defaults.DefaultSqlSession.seledtlist(DefaultSqlSession.java:147) ~[mybatis-3.5.14.jar!/:3.514] at org.apache.ibatis.session.defaults.DefaultSqlSession.selectist(DefaultSqlSession.java:142) ~[mybatis-3.5.14.jar!/:3.5.14] at jdk.internal.reflect.GeneratedMethodAccessor348.irnvoke(Unknown Source) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessonImpl.invoke(DelegatingMethodAccessorimpl.java:43) ~[na:na1 at java.base/java.lang.reflect.Method.invoke(Method.java:569)~[na:na] at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:425) ~[mybaatis-spring-3.0.3.jar!/:3.0.3] ... 276 common frames omitted
11-21
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值