现在有两张表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里面是怎么写的,看一下