java表的分组查询collection用法

温暖.jpg

最近在学习java做项目中遇到了关联查询之后要填充modl,但是model是分组的,里面有多个数组,如果只是用关联查询,对于这种会出现重复查询,所以这里要用到Mybatis的collection来处理

1、首先介绍一下我们的model属性(可以看到有2个指定对象的数组)

    private Long id;
    private String customerNo;
    private Long listId;
    private String name;
    private String identifyType;
    private String identifyNo;   
    private String phoneA;
    private String phoneB;
    private String phoneC;
    private String telephone;
    private String email;
    private String idcardAdress;
    private String householdAddress;
    private String liveAddress;
    private String workAddress;
    private Date gmtCreate;
    private Date gmtModified;
    private Long createBy;
    private Long lastUpdateBy;
    private String customerType;
    private List contactList;
    private List bankcardList;

2、在mapper里面对接输出model


    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

            
            
            
            
            
            
            
            
            
            
  
  
            
            
            
            
            
            
            
  

3、在mapper的xml里写关联查询


简单3步就完成了分组查询,其中要注意BaseResultMap1中表属性对应的要与自己创建的匿名表列名对应(区分相同字段在不同表中的情况)
详细的collection用法和Association用法可参考https://blog.csdn.net/qq_38157516/article/details/79712721

你可能感兴趣的:(java表的分组查询collection用法)