SSM时遇到的异常(10)——...Cause: ...ClassCastException: java.lang.String cannot be cast to java.lang.Integer

本文详细解析了一个在使用MyBatis框架时遇到的常见问题:在执行SQL语句过程中,由于参数类型不匹配导致的ClassCastException异常。通过具体代码示例,展示了如何定位错误来源,并提供了正确的参数类型设置方法,避免了将String类型参数错误地作为Integer类型传递给数据库,确保了应用程序的正常运行。

JDK1.7+Tomcat7.0+Eclipse+SSM+Bootstrap(含Bootstrap Table)   

三月 07, 2019 8:56:18 下午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [SpringMVC] in context with path [/HTGlory] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
### The error may exist in file [F:\ALL_Course\10Activiti\Ecli\.metadata\.plugins\org.eclipse.wst.server.core\tmp4\wtpwebapps\HTGlory\WEB-INF\classes\com\ht\lym\mapper\StudentJobsDao.xml]
### The error may involve com.ht.lym.mapper.StudentJobsDao.lists-Inline
### The error occurred while setting parameters
### SQL: select j.*,s.studName,c.className from studentjobs j inner join student s on j.studId=s.studId     left join cls c on j.classId=c.classId where studName like concat('%',?,'%') limit ?,?;
### Cause: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer] with root cause
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
	at org.apache.ibatis.type.IntegerTypeHandler.setNonNullParameter(IntegerTypeHandler.java:26)
	at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:50)	

异常里讲的提示得很明显了:

发现,还真是有错误!!! 

 上图(StudentJobsDao.java)和 下图(StudentJobsDao.xml)

改:

 补充:

为什么会出现cannot be cast to java.lang.String(另外问题的解决方案)

推荐:[也是parameterType属性错误使用导致的问题]

IllegalStateException: Optional int parameter 'id' is present but cannot be translate

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Yvette_QIU

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值