问题:

使用映射文件实现查询一对多或多对多时只返回一条数据问题

解决方法:

导致这种情况出现的问题是因为两个表中的主键是一样所以出现了数据覆盖问题。

解决方式一:修改数据库表中的主键(这种方法比较麻烦)。

解决方式二:在查询语句中修改一个表的主键使其不一致即可,例子:

表User主键为id,表Book主键为id,映射结果集时设置表Book的主键id为b_id即可。

<resultMap id="resultUserMap" type="books.com.boot.model.User">
<id property="id" column="id"/>
<result property="userName" column="user_name"/>
<result property="userPassword" column="user_password"/>
<result property="createUser" column="createuser"/>
<result property="createTime" column="createtime"/>
<result property="remark" column="remark"/>
<collection property="books" column="author" ofType="Book" >
<id property="id" column="b_id"/>
<result property="title" column="title"/>
<result property="author" column="author"/>
<result property="isbn" column="isbn"/>
<result property="isbnTime" column="isbn_time"/>
<result property="publisher" column="publisher"/>
<result property="decription" column="description"/>
<result property="createUser" column="createuser"/>
<result property="createTime" column="createtime"/>
</collection>
</resultMap>
备注:
属性property对应model类的属性名,column对应数据库表中的列名,其中id元素中的column可以修改为任意别名,result元素中的column列名必须与表列名一致。
目前id元素和result元素的区别就在这方面,其他有待补充。

mybatis报错:查询一对多或多对多时只返回一条数据的问题的更多相关文章

  1. Mybatis一对多或多对多只能查出一条数据解决策略

    原文:https://blog.csdn.net/ren814/article/details/81742242 <resultMap id="menuModelMap" t ...

  2. mybatis 关联查询时,从表只返回第一条记录解决办法

    如果两表联查,主表和明细表的主键都是id的话,明细表的多条只能查询出来第一条. 造成以上情况可能的原因: 1.级联查询的时候,主表和从表有一样的字段名的时候,在mysql上命令查询是没问题的.但在my ...

  3. [jnhs]id字段修改错误导致hibernate hql查询整表只返回第一条数据

    调试发现,查询到的就是一条数据 hql语句执行结果 Hibernate: select ballmodel0_.ball_id as ball_id1_1_, ballmodel0_.color as ...

  4. mybatis报错:A query was run and no Result Maps were found for the Mapped Statement、、Property [login_ip] not found on type [com.thinkgem.jeesite.common.permission.entity.PremissUser]问题解决

    今天在做ssm项目的时候出现了: 先是出现 了错误: mybatis报错:A query was run and no Result Maps were found for the Mapped St ...

  5. Mybatis 报错

    Mybatis 报错 builder.BuilderException: Error parsing SQL Mapper Configuration Caused by: org.apache.ib ...

  6. Mybatis报错:Could not find resource mybatis-conf.xml

    Mybatis报错:Could not find resource mybatis-conf.xml 报错截图: 报错内容: java.io.IOException: Could not find r ...

  7. SSAS中事实表中的数据如果因为一对多或多对多关系复制了多份,在维度上聚合的时候还是只算一份

    SSAS事实表中的数据,有时候会因为一对多或多对多关系发生复制变成多份,如下图所示: 图1 我们可以从上面图片中看到,在这个例子中,有三个事实表Fact_People_Money(此表用字段Money ...

  8. mybatis报错Mapped Statements collection does not contain value for com.inter.IOper

    首页 > 精品文库 > mybatis报错Mapped Statements collection does not contain value for com.inter.IOper m ...

  9. mybatis报错 Error instantiating interface com.atguigu.mybatis.dao.DepartmentMapper with invalid types () or values ()

    mybatis报错 Error instantiating interface com.atguigu.mybatis.dao.DepartmentMapper with invalid types ...

随机推荐

  1. Highcharts - Pie Chart

    1. 饼状图(Pie Chart)示例: <div id="container" style="height: 400px"></div> ...

  2. 如何开放 Azure 虚拟机 Ping 功能

    前言 文章<使用 PsPing & PaPing 进行 TCP 端口连通性测试>中提到,ICMP 协议的数据包无法通过 Azure 的防火墙和负载均衡器,所以不能直接使用 Ping ...

  3. Anaconda中spyder 安装tensorflow

    关于Anaconda的安装就不介绍了,本文主要介绍spyder中安装 tensorflow.废话少说 直接重点: 1.安装好Anaconda之后,找到spyder图标 点击install,等待安装完成 ...

  4. 如何杀掉一个用户下的所有进程并drop掉这个用户

    如何杀掉一个用户下的所有进程并drop掉这个用户 Copy the sample code below into a file named kill_drop_user.sql.Open SQL*Pl ...

  5. 如何将一个PDF文件里的图片批量导出

    假设我有下面这个PDF文件,里面有很多图片,我想把这些图片批量导出,而不是在Adobe Acrobat Reader里一张张手动拷贝: 本文介绍一种快捷做法. 用PDF-XChange Editor打 ...

  6. vue错误提示 Cannot read property 'beforeRouteEnter' of undefined,刷新后跳到首页

    vue错误提示 Cannot read property 'beforeRouteEnter' of undefined,刷新后跳到首页 因为vue-router版本太高了,我vue用的是2.3.4, ...

  7. 笔记本win8系统共享wifi上网方法

    华硕笔记本电脑,安装了win8系统,使用wifi上网,由于连接无线路由的机器太多,超过路由连接数上限,因此转为使用笔记本共享wifi方式给手机上网. 最终上网方式为: 笔记本网卡接入无线路由器上网,笔 ...

  8. HTTP 状态码 301 302

    301 Moved Permanently被请求的资源已永久移动到新位置,并且将来任何对此资源的引用都应该使用本响应返回的若干个URI之一.如果可能,拥有链接编辑功能的客户端应当自动把请求的地址修改为 ...

  9. GPU使用

    GPU .caret, .dropup > .btn > .caret { border-top-color: #000 !important; } .label { border: 1p ...

  10. 动态规划(DP),压缩状态,插入字符构成回文字符串

    题目链接:http://poj.org/problem?id=1159 解题报告: 1.LCS的状态转移方程为 if(str[i-1]==str[j-1]) dp[i][j]=dp[i-1][j-1] ...