mybatis learning: mybatis comment develop many

Entity class User:

. 1  public  class the User the implements the Serializable {
 2  
. 3      Private Integer ID;
 . 4      Private String username;
 . 5      Private a Date Birthday;
 . 6      Private String Sex;
 . 7      Private String address;
 . 8  
. 9      // many relationship mapping: a plurality of user accounts corresponding to 
10      Private List <the Account> Accounts;
 . 11  
12 is      public List <the Account> the getAccounts () {
 13 is          return Accounts;
 14      }
 15  
16     public void setAccounts(List<Account> accounts) {
17         this.accounts = accounts;
18     }
19 
20     public Integer getId() {
21         return id;
22     }
23 
24     public void setId(Integer id) {
25         this.id = id;
26     }
27 
28     public String getUsername() {
29         return username;
30     }
31 
32     public void setUsername(String username) {
33         this.username = username;
34     }
35 
36     public Date getBirthday() {
37         return birthday;
38     }
39 
40     public void setBirthday(Date birthday) {
41         this.birthday = birthday;
42     }
43 
44     public String getSex() {
45         return sex;
46     }
47 
48     public void setSex(String sex) {
49         this.sex = sex;
50     }
51 
52     public String getAddress() {
53         return address;
54     }
55 
56     public void setAddress(String address) {
57         this.address = address;
58     }
59 
60     @Override
61     public String toString() {
62         return "User{" +
63                 "id=" + id +
64                 ", username='" + username + '\'' +
65                 ", birthday=" + birthday +
66                 ", sex='" + sex + '\'' +
67                 ", address='" + address + '\'' +
68                 '}';
69     }
70 }

dao layer:

IUserDao:

 1     @Select("select * from user")
 2     @Results(id = "userMap",value = {
 3             @Result(id = true,column = "id",property = "id"),
 4             @Result(column = "username",property = "username"),
 5             @Result(column = "address",property = "address"),
 6             @Result(column = "sex",property = "sex"),
 7             @Result(column = "birthday",property = "birthday"),
 8             @Result(property = "accounts",column = "id",many = @Many(select = "cn.flypig666.dao.IAccountDao.findAccountByUid",
 9                     fetchType = FetchType.EAGER))
10     })
11     List<User> findAll();

IAccountDao:

 / ** 
     * The user account information query id 
     * @param the userId 
     * @return 
     * / 
    @Select ( "SELECT * from Account WHERE UID UID = # {}" ) 
    List <the Account> findAccountByUid (Integer the userId); 
}

 

Guess you like

Origin www.cnblogs.com/flypig666/p/11506519.html