问题:

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

解决方法:

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

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

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

表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. 菜鸟学习Spring——SpringMVC注解版将URL中的参数转成实体

    一.概述 将URL中参数转成实体在我们项目中用的很多比如界面提交表单请求后台的Contorller的时候通过URL传递了一串参数到后台,后台通过Spring让界面的字段与实体的字段映射来实现给后台的实 ...

  2. Eclipse org.eclipse.compare plug-in

    Plug-in metedata tell eclipse runtime kernel how to create a expected object and set its perperties, ...

  3. 03_CronTrigger

    [Cron表达式] Quartz使用类似于Linux下的Cron表达式定义的时间规则,Cron表达式由6到7个空格分隔的时间字段组成. [ 字符说明 ] * :可以用在所有字段中,表示对应时间域内的每 ...

  4. Jmeter(一)http接口添加header和cookie --转载

    Jmeter(一)http接口添加header和cookie   HTTP信息头管理器在Jmeter的使用过程中起着很重要的作用,通常我们在通过Jmeter向服务器发送http请求(get或者post ...

  5. 设计模式之装饰模式(Decorator)

    1. 装饰者模式,动态地将责任附加到对象上.若要扩展功能,装饰者提供了比继承更加有弹性的替代方案. 2.组合和继承的区别 继承.继承是给一个类添加行为的比较有效的途径.通过使用继承,可以使得子类在拥有 ...

  6. LESS初体验

    将一个变量赋值给另一个变量,用引号:@white: 'color-white';,使用另一个变量,需要双@@符号:p {color: @@white;}. 而以这样进行变量的赋值:@white: @c ...

  7. 在centos7中安装redis,并通过node.js操作redis

    引言 最近在学习node.js 连接redis的模块,所以尝试了一下在虚拟机中安装cent OS7,并安装redis,并使用node.js 操作redis.所以顺便做个笔记. 如有不对的地方,欢迎大家 ...

  8. spring boot拦截器配置

    1.在spring boot配置文件application.properties中添加要拦截的链接 com.url.interceptor=/user/test 2.编写拦截器代码 ,创建UrlInt ...

  9. O/S-Error: (OS 23) Data error (cyclic redundancy check)问题处理

    RMAN-03002: backup plus archivelog 命令 (在 08/24/2015 03:31:00 上) 失败ORA-19501: 文件 "XXXXXX.DBF&quo ...

  10. WP模拟器修改语言为中文方法

    对于WP7模拟器来说默认启动时显示的语言为英文,除了操作界面外,如果你的应用支持多国语言必须修改为中文才能显示正确的界面.下面Zune123将WP7 Emulator修改语言为中文的方法写个简单的教程 ...