A query was run and no Result Maps were found for the Mapped Statement

错误提示

Exception in thread "main" 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 'mapper.StudentMapper.selectStudentsByClazzId'.  It's likely that neither a Result Type nor a Result Map was specified.
### The error may exist in mapper/StudentMapper.xml
### The error may involve mapper.StudentMapper.selectStudentsByClazzId

分析原因

mapper.StudentMapper.selectStudentsByClazzId这条语句没有设置参数和返回值

错误代码

/OneToManyTest3/src/mapper/StudentMapper.xml
1
2
3
4
<select id="selectStudentsByClazzId">
select * from tb_student
<where>clazz_id=#{clazz_id}</where>
</select>

解决方案

给selectStudentsByClazzId语句加上参数和返回值声明:

<select id="selectStudentsByClazzId" parameterType="int"
    resultMap="studentMap">
    select * from tb_student
    <where>clazz_id=#{clazz_id}</where>
</select>