springboot中mybatis报错

反正有关于mybatis报错的,问题肯定就是mybatis这几个文件之中。 要么就是Mapper类少注解,要么就是mybatis配置文件中的namespace

java.lang.IllegalArgumentException: Result Maps collection does not contain value for com.mao.mapper.BrMapper.Br

[Request processing failed; nested exception is java.lang.IllegalArgumentException: Result Maps collection does not contain value for com.mao.mapper.BrMapper.Br] with root cause

原因

使用mybatis报错

java.lang.IllegalArgumentException: Result Maps collection does not contain value for com.xxx.mapper.xxxMapper.xxx

at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:853) ~[mybatis-3.4.0.jar:3.4.0]

at org.apache.ibatis.session.Configuration.getResultMap(Configuration.java:605) ~[mybatis-3.4.0.jar:3.4.0]

at org.apache.ibatis.builder.MapperBuilderAssistant.getStatementResultMaps(MapperBuilderAssistant.java:344)

  1. 在mapper.xml文件中,将 resultType 和 resultMap 弄混淆。

这个原因一般报错的第一行后面都会有这样一句话 org.apache.ibatis.builder.IncompleteElementException: Could not find result map com.xxx.xxx with root cause

注意:使用resultMap时,必须要有标签指明id和返回类型以及表字段的对应关系。

      如果是直接返回一个用户定义的实体类型,则要使用resultType,弄混淆就会报错。

      检查写的Mapper文件是不是全部返回值错误,每一个都要检查 ,希望大家以后都不要再犯这种错误 !
  1. 在mapper.xml头部namespace引入错误。

这个namespace引入的mapper文件要和你的mapper.xml文件对应。

No MyBatis mapper was found in '[com.mao]' package. Please check your configuration.
没有在Mapper类上使用 @Mapper注解,只用了@Repository

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.mao.mapper.PatientMapper.selectAll
这里的语句不匹配 原因: 我这里的namespace写错了,在mapper包下 我写成了pojo包

<mapper namespace="com.mao.pojo.PatientMapper">
    <select id="selectAll" resultType="Patient">
        select * from patient
    </select>
</mapper>
posted @ 2022-03-30 21:45  没有烦恼的猫猫  阅读(510)  评论(0)    收藏  举报