视频不完整……另外插入可以,但是查询修改删除报错,有人遇到一样的错误吗?
同一个错误,就讲讲查询好了
controller里的映射代码段:
@RequestMapping("/queryuser")
public User queryUser(String id) throws Exception{
return userService.queryUserById(id);
}
serviceImpl的代码段
@Transactional(propagation = Propagation.SUPPORTS)
public User queryUserById(String id) throws Exception{
return userMapper.selectByPrimaryKey(id);
}
代码这么简单了……怎么会出错的?错误如下:
这是网页的反馈:
{
"timestamp": "2018-11-23T18:04:30.660+0000",
"status": 500,
"error": "Internal Server Error",
"message": "nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='age', mode=IN, javaType=class java.lang.Integer, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #5 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer",
"path": "/mybatis/queryuser"
}
这是eclipse的错误
org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet]: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='age', mode=IN, javaType=class java.lang.Integer, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #5 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. 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
这里在说age属性的jdbcType是Integer,然后不能由String转Integer,但是那个xxmapper.xml是自动生成的,视频里老师也没改过,我用String的ID查出来User对象,不是应该直接显示成JSON吗?为什么需要转age属性?百度了一下,发生这个错误的原因各不相同,看到的朋友请赐教