Mybatis--多表查询

一、一对一查询

1.实体类


public class User {
    private int id;
    private String username;
    private Date birthday;
    private String address;
    private String sex;
}
public class Account  {
    private int id;
    private int uid;
    private double money;
    private User user;
}

2.映射类

public interface IAccountDao {
    /**
     * 查询所有账户
     */
    public List findAll();
}

3.表结构

[图片上传失败...(image-bbcc2c-1554098740524)]

4.xml配置




    
        
        
        
        
            
            
            
            
            
        
    
    

二、一对多查询

1.实体类

public class User {
    private int id;
    private String username;
    private Date birthday;
    private String address;
    private String sex;
    private List accounts;
}
public class Account  {
    private int id;
    private int uid;
    private double money;
}

2.XML配置

 
        
        
        
        
        
        
            
            
            
        
    
    
    

三、多对多查询

1.表结构

blob.jpg

2.实体类

public class Role {
    private int id;
    private String role_name;
    private String role_desc;
    private List users;

映射配置文件





    
        
        
        
        
            
            
            
            
            
        
    

    

4.映射类

public interface IRoleDao {
    /**
     * 查找所有角色
     */
    public List findAll();
}

四、延迟加载

一对多


一对一


你可能感兴趣的:(Mybatis--多表查询)