HaoBiaoSheng 2015-07-27 02:28 采纳率: 0%
浏览 11926

求助:mybatis association 关联查询时,只返回第一条记录

1、这个是配置文件

<resultMap type="User" id="userResultMap">
    <!-- 属性名和数据库列名映射 -->
    <id property="id" column="id"  />
    <result property="userName" column="userName"  />
    <result property="userPwd" column="userPwd" />
</resultMap>

<resultMap type="Article" id="articleResultMap" >
    <id property="id" column="id" />
    <result property="title" column="title" />
    <result property="content" column="content" />
    <!-- 将article的user属性映射到userResultMap -->
    <association property="user" resultMap="userResultMap" /> 
</resultMap>

<!--查询-->
<select id="getUserArticles" parameterType="int" resultMap="articleResultMap" >
    select user.id,user.userName,user.userPwd,article.title,article.content
    from user,article where user.id = article.userId and user.id = #{id}
</select>

2、select user.id,user.userName,user.userPwd,article.title,article.content
from user,article where user.id = article.userId and user.id = 1 这条sql语句在mysql中查询是有5条记录的,但是在代码中就只有一条记录

3、public List getUserArticles(int id);
这个是接口

  • 写回答

10条回答

  • zjq78577117 2015-07-27 02:34
    关注

    你的id是user表里面的主键吧,怎么查也不会有五条记录吧

    评论

报告相同问题?

悬赏问题

  • ¥15 Error in check.length("fill") : 'gpar'成分'fill'的长度不能为零
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导