今天学mybatis,出现了如下错误提示:
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were found for the Mapped Statement 'com.wwl.mybatis.mapper.ParameterMapper.CheckLogin'. It's likely that neither a Result Type nor a Result Map was specified.
而且我日志提示我前面查找SQL语句没问题,就是最后一步输出错误, 所以定位为形式输出问题。
在这里我加上了resultType来表示返回类型,程序就正常运行了。
(原先要输入User类的全类名,这里我用TypeAliases起了别名)
可以用resultType和resultMap两种类型,区别如下(都是用来建立联系的)
resultType:自动映射,用于属性名和表中字段名一致的情况
resultMap:自定义映射,用于一对多或多对一或字段名和属性名不一致的情况