Mybatis报错—— A query was run and no Result Maps were found for the Mapped Statement

9 篇文章 0 订阅
9 篇文章 0 订阅

Mybatis报错—— A query was run and no Result Maps were found for the Mapped Statement 。。。 It’s likely that neither a Result Type nor a Result Map was specified.

报错如下

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.mapper.EmployeeMapper.getEmpByIdAndLastname'.  It's likely that neither a Result Type nor a Result Map was specified.
### The error may exist in com/mapper/EmployeeMapper.xml
### The error may involve com.mapper.EmployeeMapper.getEmpByIdAndLastname
### The error occurred while handling results
### SQL: select * from tbl_employee where id = ? and last_name=?
### Cause: org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were found for the Mapped Statement 'com.mapper.EmployeeMapper.getEmpByIdAndLastname'.  It's likely that neither a Result Type nor a Result Map was specified.
    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
    ... 29 more

异常分析:
关键在第一段提示: It’s likely that neither a Result Type nor a Result Map was specified.意思是无法确定返回值类型。
如下代码:

<select id="getEmpById" >
    select * from tbl_employee where id = #{id}
</select>

在写select查询标签是,没加resultType属性。

异常解决,代码如下:

<select id="getEmpById" resultType="com.bean.Employee" >
    select * from tbl_employee where id = #{id}
</select>

小结:
在写select查询标签进行查询时,必须写resultType属性,不然mybatis无法确定返回值类型,就会报错。

补充:
1.进行查询时,resultType(返回值类型)属性不能省略。
2.进行增删改时,parameterType(参数类型)属性可以省略,且它们没有resultType属性,返回值可以直接在Mapper接口上定义。

mybatis允许增删改查直接定义以下类型返回值(Mapper接口中定义)
Integer(返回SQL语句影响的行数)、
Long(同上)
Boolean(返回SQL语句是否执行成功)

<!-- parameterType:参数类型,可以省略  -->
<insert id="addEmp" parameterType="com.bean.Employee">
    INSERT INTO tbl_employee 
    VALUES (#{lastName}, #{gender},#{email});   
</insert>
  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值