Mybatis 报错:A query was run and no Result Maps were found for the Mapped Statement ‘com.wanuw.mapper.

  • Post author:
  • Post category:其他


运行Mybatis时出现:A query was run and no Result Maps were found for the Mapped Statement ‘com.wanuw.mapper.EmpMapper.selectAll’.  It’s likely that neither a Result Type nor a Result Map was specified.错误

XML原代码:

<select id="selectAll">
    select
        <include refid="emp_column"/>
    from emp
    <where>
        <if test="name != null">name like concat('%', #{name}, '%')</if>
        <if test="gender != null">and gender = #{gender}</if>
        <if test="begin != null and end != null">and entrydate between #{begin} and #{end}</if>
    </where>
</select>

出现原因是缺少resultType/resultMap,也就是需要一个特定的返回类型。


1)有可能是Integer,也有可能是String,若是通用的类型   直接添加相应的 类型标签   如:


<select id=”selectAll” resultType=”String”>


2)若是返回应用类型的数据类型,需要添加此类型的全包名,如:


<select id=”selectAll” resultType=”com.wanuw.pojo.Emp”>

———————————————-分割线—————————————

获取全包名方法:

1.打开自定义的引用类型文件

2.鼠标放置到Emp名(


你们的需要根据实际类名


)然后右键点击,选择:

3.粘贴到

resultType=””标签中就行了


————————————————-分割线———————————————–


正确的样子:

<select id="selectAll" resultType="com.wanuw.pojo.Emp">
    select
        <include refid="emp_column"/>
    from emp
    <where>
        <if test="name != null">name like concat('%', #{name}, '%')</if>
        <if test="gender != null">and gender = #{gender}</if>
        <if test="begin != null and end != null">and entrydate between #{begin} and #{end}</if>
    </where>
</select>

主要是记录之用,若是能帮到更多人就更好。



版权声明:本文为ytgytg28原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。