Moon…… 2024-02-26 16:24 采纳率: 57.1%
浏览 65
问题最晚将于03月05日00:00点结题

Result Maps collection does not contain value for Mapper.patientsMapper.BrandResultMap 一直出现这个提示

Result Maps collection does not contain value for Mapper.patientsMapper.BrandResultMap
一直出现这个提示,不知道到底哪里错了

@Data
public class patientsEntity {
private int id;
private String name;
private int age;
private String inTime;
private int TMSvalue;
private boolean status;
private String outTime;
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
    PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="Mapper.patientsMapper">
    <resultMap id="brandResultMap" type="entity.patientsEntity">
        <id column="id" property="id"/>
        <result column="name" property="name"/>
        <result column="age" property="age"/>
        <result column="inTime" property="inTime"/>
        <result column="TMSvalue" property="TMSvalue"/>
        <result column="status" property="status"/>
        <result column="outTime" property="outTime"/>
    </resultMap>

    <!--对所有数据进行查询展示-->
    <select id="Search" parameterType="entity.patientsEntity" resultMap="BrandResultMap">
        select * from `info`;
    </select>
</mapper>

数据库:

img

idea:

img

  • 写回答

8条回答 默认 最新

  • 檀越@新空间 2024-02-26 16:25
    关注

    Moon…… 下午好🌅🌅🌅
    本答案参考通义千问

    **问题:**在使用MyBatis时,Result Maps collection does not contain value for Mapper.patientsMapper.BrandResultMap 这个错误提示表明你的Mapper文件中定义的BrandResultMap结果映射没有被正确识别或引用。

    解决方案:

    1. 检查XML映射文件

      • 确保 <resultMap> 标签中的 id 属性与你在Java代码中引用的BrandResultMap名称匹配。在XML中,你的resultMap定义如下:
        <resultMap id="brandResultMap" type="entity.patientsEntity">
          ...
        </resultMap>
        
      • 检查 <select> 标签中的 resultMap 引用是否正确,应是 resultMap="brandResultMap" 而不是 resultMap="BrandResultMap"(大小写敏感):
        <select id="Search" parameterType="entity.patientsEntity" resultMap="brandResultMap">
          select * from `info`;
        </select>
        
    2. 确保patientsMapper命名空间正确

      • 确认<mapper namespace="Mapper.patientsMapper"> 中的命名空间与Java类文件中的一致。如果在patientsMapper.java中,应是 @Mapper 注解的 namespace 属性:
        @Mapper
        public interface patientsMapper {
            ...
        }
        
    3. 检查patientsEntity

      • 确保patientsEntity类的全限定名与type属性中的entity.patientsEntity匹配:
        <resultMap id="brandResultMap" type="com.example.demo.entity.patientsEntity">
          ...
        </resultMap>
        
    4. 清理缓存和重新编译

      • 关闭IDEA并重启,或者尝试清理IDEA的编译缓存和Maven/Gradle的项目构建。

    如果以上步骤都检查无误,但问题依然存在,可能需要检查是否有其他地方的代码误用了BrandResultMap,或者是否在不同Mapper文件中定义了同名的结果映射。如果问题仍然无法解决,可以考虑查看MyBatis的官方文档或者搜索社区中的类似问题,可能有其他解决方案。

    评论

报告相同问题?

问题事件

  • 已采纳回答 2月26日
  • 创建了问题 2月26日