日期:2014-05-17  浏览次数:20694 次

帮忙看下mybatis查出的数据为什么是一条
test_user表:

id username userage useraddress
1    wjf       29       通州
2    tbf       30       湖北
3    xxx       23       xxxxxx

关联:
test_article表:

id   userid   title       content
1     1     test_title   test_content
2     1     test_title2  test_content2
3     1     test_title3  test_content3
4     1     test_title4  test_content4

User类:

public class User {

private int id;
private String username;
private int userage;
private String useraddress ;
        get和set方法...
}

Article类:

public class Article {

    private int id;
    private User user;
    private String title;
    private String content;
    get和set方法...
}

目的是查出1号用户对应的article:
User.xml配置:

     <resultMap id="resultUserArticleList" type="Article">
       <id property="id" column="id" />
         <result property="title" column="title" />
         <result property="content" column="content" />
         
         <association property="user" javaType="User">
             <id property="id" column="id" />
             <result property="username" column="userName" />
             <result property="useraddress" column="userAddress" />             
         </association>             
     </resultMap>
     
     <select id="getUserArticles" parameterType="int" resultMap="resultUserArticleList">
      select u.id,u.username,u.useraddress,a.id,a.title,a.content from test_user u ,test_article a 
               where u.id=a.userid and u.id=#{id}
     </select>

接口:

public interface IUserOperation {
public List&l