用sql直接查数据库有多条 在项目中mybatis嵌套查询查出来只有1条是为什么

小酱油啦啦啦啦啦 2016-07-16 04:46:41
j

public PageInfo<MourningRecord> getMourningRecordPageInfo(Map<String, Object> paramMap,int pageNum,int pageSize,String order){
PageHelper.startPage(pageNum, pageSize);//设置分页
PageHelper.orderBy(order);
List<MourningRecord> list=mourningRecordMapper.getMourningRecordListMap(paramMap);
PageInfo<MourningRecord> page=new PageInfo<MourningRecord>(list);
return page;

}


<select id= "getMourningRecordListMap" resultMap="MourningRecordListMapper">
select c.`name`,c.`schedule_flag`,c.`cremation_time`,c.`age`,c.`sex`,b.`name` as bname,m.`begin_time` from y_mourning_record m,y_commission_order c,ba_mourning b where m.commission_order_id = c.id and m.mourning_id=b.id
<if test="flag!=null and flag!=''">
and m.flag=#{flag}
</if>
<if test="beginDate!=null and beginDate!='' and endDate!=null and endDate!=''">
and ( ( m.begin_time >= #{beginDate} and m.begin_time <= #{endDate} )
or ( m.end_time >= #{beginDate} and m.end_time <= #{endDate} )
or ( m.begin_time <= #{beginDate} and m.end_time >= #{endDate} ))
</if>
<if test="mourningbeginDate !=null and mourningbeginDate != '' and mourningendDate !=null and mourningendDate != '' ">
and ( m.begin_time >=#{mourningbeginDate} )
and ( m.begin_time <= #{mourningendDate} )
</if>
<if test="searchType !=null and searchType != '' and searchType=='1'.toString() ">
and c.name like CONCAT('%', #{searchVal},'%')
</if>
<if test="searchType !=null and searchType != '' and searchType=='2'.toString() ">
and b.name like CONCAT('%', #{searchVal},'%')
</if>
</select>

<resultMap id="MourningRecordListMapper" type="MourningRecord">
<id property="id" column="id" />
<result property="mourningId" column="mourning_id" />
<result property="beginTime" column="begin_time" />
<result property="createUserId" column="create_user_id" /> -->
<result property="commissionOrderId" column="commission_order_id" />
<result property="flag" column="flag" />
<association property="order" javaType="CommissionOrder">
<id property="id" column="id"/>
<result property="name" column="name" />
<result property="cardCode" column="card_code" />
<result property="sex" column="sex" />
<result property="cremationTime" column="cremation_time" />
<result property="age" column="age" />
<result property="scheduleFlag" column="schedule_flag" />
</association>
<association property="mourning" javaType="Mourning">
<id property="id" column="id" />
<result property="name" column="bname" />
</association>
</resultMap>

navicat结果
项目显示结果
奇怪的是page里面的total条数有4条 但是page里面的list只有一个对象
...全文
926 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
我也遇到同样的问题,但我的是将 SELECT 字段 FROM 表名 WHERE 筛选条件 中想查询的字段直接换成* 即 SELECT * FROM 表名 WHERE 筛选条件 。这样就解决了。 字段可以多,但不能少。因为多的话你可以用实体类装起来,然后调用数据库表字段对应的实体类属性获取即可,一样不受影响。 这问题,今下午可费了我两三个小时。希望能帮到以后遇到同样问题的人
hyx1221 2019-09-16
  • 打赏
  • 举报
回复
你必须得让你关联的三张表的id都是查询的返回 select a.id as a_id ,b.id as b_id ,c.id as c_id,...... from .... 然后column=“a_id”....
hyx1221 2019-09-16
  • 打赏
  • 举报
回复
resultMap里的id属性 以及其他两个id属性的colum不能一直 在数据库查询返回结果时as一个别名就行了
hyx1221 2019-09-16
  • 打赏
  • 举报
回复
给关联的表出现重复字段名的字段起别名 然后 column=“别名”
鸡公山汤圆 2019-04-29
  • 打赏
  • 举报
回复
引用 7 楼 f45056231p 的回复:
在采用嵌套结果的方式查询一对一、一对多关系时,必须要通过resultMap下的id或result标签来显式设置属性/字段映射关系,否则在查询多条记录时会仅仅返回最后一条记录的情况。

这个试过了。。不行啊。。控制台显示4条记录。。页面只显示一条。。
f45056231p 2018-07-29
  • 打赏
  • 举报
回复
在采用嵌套结果的方式查询一对一、一对多关系时,必须要通过resultMap下的id或result标签来显式设置属性/字段映射关系,否则在查询多条记录时会仅仅返回最后一条记录的情况。
  • 打赏
  • 举报
回复
后来自己找到了解决办法 就是resultMap 中result属性不能多于你sql中所查的字段。 原因不明
syhleo 2017-03-03
  • 打赏
  • 举报
回复
 <resultMap id="MourningRecordListMapper" type="MourningRecord">中 你是要出现多个property="order" . 就把  <association  改为<collection 这样才能出现多个order
bazinge 2017-03-03
  • 打赏
  • 举报
回复
楼主解决了吗,我也出现了这种错误
非满一不非 2016-07-25
  • 打赏
  • 举报
回复
楼主解决没有,我也遇到了这样的问题。
bree06 2016-07-17
  • 打赏
  • 举报
回复
看一下pageNum, pageSize这两个参数是否是正确的。
  • 打赏
  • 举报
回复
....................

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧