SQL没有指定返回结果类型的映射

错误提示:

A query was run and no Result Maps were found for the Mapped Statement 'com.example.ie.mapper.Mapper.selectDigCategoryData'. It's likely that neither a Result Type nor a Result Map was specified.

上面的MyBatis XML映射文件中的代码可以查询表中数据的数量。

而你的报错信息是因为在定义 SQL 语句时,没有指定返回结果类型的映射。你需要添加一个结果映射来指定查询返回结果类型。

可以在resultMap中定义一个结果集映射,指定查询返回结果类型为整型(int),如下所示:

原来错误示范(Mapper.xml),此处没有

resultMap
 
 
<select id="selectDigCategoryData" parameterType="com.example.ie.entity.DigCategoryData">
    select count(*) from digcategorydata;
</select>

解决方案

<resultMap id="countResultMap" type="Integer"/>

<select id="selectDigCategoryData" parameterType="com.example.ie.entity.DigCategoryData" resultMap="countResultMap">
    select count(*) from digcategorydata;
</select>

猜你喜欢

转载自blog.csdn.net/Isonion/article/details/134288325
今日推荐