问题:

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

解决方法:

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

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

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

表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元素的区别就在这方面,其他有待补充。

最新文章

  1. jquery easyui-datagrid/treegrid 清空数据参考
  2. POJ3208:Apocalypse Someday
  3. 录制简单的自动化测试工具SlikMobile初体验
  4. 纯手工打造(不使用IDE)java web 项目
  5. repo: 创建local manifest以及如何添加app到CM/Android build系统中
  6. 应中DOS中断显示字符串(摘自《汇编语言》王爽)
  7. solr 相似查询-MoreLikeThis
  8. 1019.Line Painting(线段树 离散化)
  9. virtualbox+centos 7 实现宿主机器互通
  10. myeclipse2015 安装配置
  11. 我的学习之路_第二十章_JDBC
  12. cookie和session(一)
  13. 在ARC下,assign和weak的区别
  14. django-restframework之缓存系统
  15. MD5 Hashing in Java
  16. three.js 第二篇:场景 相机 渲染器 物体之间的关系
  17. python自学第12天 模块
  18. 返回Json格式结果
  19. C# 编写WCF简单的服务端与客户端
  20. Git文件状态

热门文章

  1. 五款app原型设计工具对比
  2. 跨平台移动开发_PhoneGap 再次点击返回键切换到桌面效果
  3. wxpython grid
  4. 【Spring实战】—— 1 入门讲解
  5. 7.Zabbix 3.0 web监控
  6. GitLab 数据备份和恢复
  7. March 1 2017 Week 9 Wednesday
  8. Python3基本数据类型(四、元组)
  9. 【转】Dalvik虚拟机的启动过程分析
  10. About me and this site(2018/8/28)