public class Test {
public static void main(String[] args) {
//获取session对象
SqlSession session = GetSqlSession.createSqlSession();
//得到对应Mapper
UserMapper userMapper=session.getMapper(UserMapper.class);
//调用方法
User user = userMapper.queryUserByName("zhangsan");
System.out.println(user);
}
}
出现以下错误:
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'userName' from result set. Cause: java.sql.SQLDataException: Cannot determine value type from string 'zhangsan'
### The error may exist in com/xxxx/mapper/UserMapper.xml
### The error may involve com.xxxx.mapper.UserMapper.queryUserByName
### The error occurred while handling results
### SQL: select * from tb_user where userName = ?
### Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'userName' from result set. Cause: java.sql.SQLDataException: Cannot determine value type from string 'zhangsan'
解决办法:
1.看mapper的配置文件:parameterType="String"是否写成parameterMap=“String”
2.看自己数据类型有没有搞错
例如:
private String userName写成private Integer userName