当前位置: 代码迷 >> J2EE >> mybatis的关联查询有关问题
  详细解决方案

mybatis的关联查询有关问题

热度:42   发布时间:2016-04-17 23:09:33.0
mybatis的关联查询问题
现在有两张表user和article,我想根据user的id来查询发过的帖子。

<select id="selectArticles" parameterType="int" resultMap="selectUserArticleList">
select t1.id,t1.userName,t1.userAddress,t2.id,t2.title,t2.content
from user t1,article t2
where t2.userid = t1.id and t1.id = #{id}
</select>

<!-- 关联查询的学习 多对一的查询-->
<resultMap type="Article" id="selectUserArticleList">
<id column="id" property="id"/>
<result column="title" property="title"/>
<result column="content" property="content"/>

<association property="user" javaType="User">
<id column="id" property="id" />
<result column="userName" property="userName" />
<result column="userAddress" property="userAddress" />
</association>
</resultMap>

把上面的select语句在数据库中执行得到了4条记录,但是通过单元测试的方式只能得到1条记录,找了半天没有找到原因。

而且在xml文件中 t2.userid 显示The word 'userid' is not correctly spelled,但是数据库确实是这个字段

找不到原因,求助一下

顺便求推荐学习mybatis的书籍,之前有过Hibernate的开发经验,谢谢
------解决思路----------------------
t2.userid   是不是userId 哦
------解决思路----------------------

<select id="selectArticles" parameterType="int" resultMap="selectUserArticleList2">
这个resultMap里面是怎么写的,看一下
  相关解决方案