开发者社区> 问答> 正文

Mybatis如何调用selectByPrimaryKey(Object key)?报错

我写了个demo

public interface UserMapper extends Mapper<User>

注意是继承了Mapper,它里面已经有一个 selectByPrimaryKey方法

然后我这么调用

User u = userMapper.selectByPrimaryKey(1);

给我报错  哭了


报错信息如下

DEBUG - Fetching JDBC Connection from DataSource

<p style="font-size:18px;font-family:'Trebuchet MS';">
	DEBUG - JDBC Connection [jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8, UserName=root<a class="referer" target="_blank">@localhost</a> , MySQL Connector Java] will not be managed by Spring
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	DEBUG - ==>  Preparing: SELECT id,name,age FROM User WHERE (id = ? AND name = ? AND age = ? ) 
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	DEBUG - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3b71d667]
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	DEBUG - Returning JDBC Connection to DataSource
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	DEBUG - Resolving exception from handler [public java.lang.String com.zqws.app.trade.controller.TestController.test(org.springframework.ui.Model,com.github.pagehelper.PageInfo)]: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### Error querying database.  Cause: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### The error may exist in com/zqws/app/trade/mapper/UserMapper.java (best guess)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### The error may involve com.zqws.app.trade.mapper.UserMapper.selectByPrimaryKey-Inline
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### The error occurred while setting parameters
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### SQL: SELECT id,name,age FROM User WHERE (id = ? AND name = ? AND age = ? )
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### Cause: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	DEBUG - Resolving exception from handler [public java.lang.String com.zqws.app.trade.controller.TestController.test(org.springframework.ui.Model,com.github.pagehelper.PageInfo)]: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### Error querying database.  Cause: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### The error may exist in com/zqws/app/trade/mapper/UserMapper.java (best guess)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### The error may involve com.zqws.app.trade.mapper.UserMapper.selectByPrimaryKey-Inline
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### The error occurred while setting parameters
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### SQL: SELECT id,name,age FROM User WHERE (id = ? AND name = ? AND age = ? )
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### Cause: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	DEBUG - Resolving exception from handler [public java.lang.String com.zqws.app.trade.controller.TestController.test(org.springframework.ui.Model,com.github.pagehelper.PageInfo)]: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### Error querying database.  Cause: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### The error may exist in com/zqws/app/trade/mapper/UserMapper.java (best guess)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### The error may involve com.zqws.app.trade.mapper.UserMapper.selectByPrimaryKey-Inline
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### The error occurred while setting parameters
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### SQL: SELECT id,name,age FROM User WHERE (id = ? AND name = ? AND age = ? )
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### Cause: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	DEBUG - Could not complete request
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';color:#0433FF;">
	org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### Error querying database.  Cause: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### The error may exist in com/zqws/app/trade/mapper/UserMapper.java (best guess)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### The error may involve com.zqws.app.trade.mapper.UserMapper.selectByPrimaryKey-Inline
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### The error occurred while setting parameters
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### SQL: SELECT id,name,age FROM User WHERE (id = ? AND name = ? AND age = ? )
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### Cause: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at com.sun.proxy.$Proxy86.selectOne(Unknown Source)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:163)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:68)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at com.sun.proxy.$Proxy92.selectByPrimaryKey(Unknown Source)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at com.zqws.app.trade.controller.TestController.test(TestController.java:25)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at java.lang.reflect.Method.invoke(Method.java:483)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:777)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1736)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1695)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at java.lang.Thread.run(Thread.java:745)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';color:#0433FF;">
	Caused by: org.apache.ibatis.exceptions.PersistenceException: 
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### Error querying database.  Cause: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### The error may exist in com/zqws/app/trade/mapper/UserMapper.java (best guess)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### The error may involve com.zqws.app.trade.mapper.UserMapper.selectByPrimaryKey-Inline
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### The error occurred while setting parameters
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### SQL: SELECT id,name,age FROM User WHERE (id = ? AND name = ? AND age = ? )
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### Cause: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:111)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:66)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at java.lang.reflect.Method.invoke(Method.java:483)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>... 52 more
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.type.StringTypeHandler.setNonNullParameter(StringTypeHandler.java:26)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:50)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:81)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:80)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:61)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:74)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:59)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:77)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at java.lang.reflect.Method.invoke(Method.java:483)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at com.github.pagehelper.SqlUtil._processPage(SqlUtil.java:351)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at com.github.pagehelper.SqlUtil.processPage(SqlUtil.java:329)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at com.github.pagehelper.PageHelper.intercept(PageHelper.java:150)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:60)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at com.sun.proxy.$Proxy93.query(Unknown Source)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at java.lang.reflect.Method.invoke(Method.java:483)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at tk.mybatis.mapper.mapperhelper.MapperOnceInterceptor.intercept(MapperOnceInterceptor.java:81)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:60)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at com.sun.proxy.$Proxy93.query(Unknown Source)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>... 59 more
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	DEBUG - Returning cached instance of singleton bean 'sqlSessionFactory'
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	八月 01, 2015 5:02:43 下午 org.apache.catalina.core.StandardWrapperValve invoke
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	严重: Servlet.service() for servlet [springmvc] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### Error querying database.  Cause: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### The error may exist in com/zqws/app/trade/mapper/UserMapper.java (best guess)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### The error may involve com.zqws.app.trade.mapper.UserMapper.selectByPrimaryKey-Inline
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### The error occurred while setting parameters
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### SQL: SELECT id,name,age FROM User WHERE (id = ? AND name = ? AND age = ? )
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	### Cause: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String] with root cause
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.type.StringTypeHandler.setNonNullParameter(StringTypeHandler.java:26)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:50)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:81)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:80)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:61)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:74)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:59)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:77)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at java.lang.reflect.Method.invoke(Method.java:483)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at com.github.pagehelper.SqlUtil._processPage(SqlUtil.java:351)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at com.github.pagehelper.SqlUtil.processPage(SqlUtil.java:329)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at com.github.pagehelper.PageHelper.intercept(PageHelper.java:150)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:60)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at com.sun.proxy.$Proxy93.query(Unknown Source)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at java.lang.reflect.Method.invoke(Method.java:483)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at tk.mybatis.mapper.mapperhelper.MapperOnceInterceptor.intercept(MapperOnceInterceptor.java:81)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:60)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at com.sun.proxy.$Proxy93.query(Unknown Source)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:66)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at java.lang.reflect.Method.invoke(Method.java:483)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at com.sun.proxy.$Proxy86.selectOne(Unknown Source)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:163)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:68)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at com.sun.proxy.$Proxy92.selectByPrimaryKey(Unknown Source)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at com.zqws.app.trade.controller.TestController.test(TestController.java:25)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at java.lang.reflect.Method.invoke(Method.java:483)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:777)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1736)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.r
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';color:#0433FF;">
	un(NioEndpoint.java:1695)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
</p>
<p style="font-size:18px;font-family:'Trebuchet MS';">
	<span> </span>at java.lang.Thread.run(Thread.java:745)
</p>
<div>
	<br>
</div>

展开
收起
爱吃鱼的程序员 2020-06-12 15:27:25 710 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    已解决 实体类id属性上少加了@Id然后mybatis不知道哪个是主键了

    where后面不要()试下自己不用写sql的,那个userMapper继承了一个Mapper,我自己写的Mapper都不用写selectByPrimaryKey方法直接调用Mapper的, 难道不是因为这吗  java.lang.Integercannotbecasttojava.lang.String试下  Useru=userMapper.selectByPrimaryKey("1");

    可能是因为你没有让mybatis知道哪个属性是主键,所以会出现  SELECTid,name,ageFROMUserWHERE(id=?ANDname=?ANDage=?)。

    如果指明了id是主键,可能sql就是 SELECTid,name,ageFROMUserWHERE(id=?)。

    @Id
        
         private
         Integer
         id
         
          ;
         
        


    我的猜测,可以检查下

    2020-06-12 15:27:42
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Java Spring Boot开发实战系列课程【第6讲】:Spring Boot 2.0实战MyBatis与优化(Java面试题) 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载