MyBatis一对多查询

1、用户实体

package com.qf.meeting.pojo;
import java.io.Serializable;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
 
public class User implements Serializable{
	private final static Logger LOG = LogManager.getLogger(User.class);
	private Integer userId;
	private String userLoginName;
	private String userTel;
	private String userPwd;
	private String photo;
	private String userName;
	private Delegation delegation;
	public User() {
		super();
	}
	public User(Integer userId, String userLoginName, String userTel, String userPwd, String photo, String userName,
			Delegation delegation) {
		super();
		this.userId = userId;
		this.userLoginName = userLoginName;
		this.userTel = userTel;
		this.userPwd = userPwd;
		this.photo = photo;
		this.userName = userName;
		this.delegation = delegation;
	}
	public Integer getUserId() {
		return userId;
	}
	public void setUserId(Integer userId) {
		this.userId = userId;
	}
	public String getUserLoginName() {
		return userLoginName;
	}
	public void setUserLoginName(String userLoginName) {
		this.userLoginName = userLoginName;
	}
	public String getUserTel() {
		return userTel;
	}
	public void setUserTel(String userTel) {
		this.userTel = userTel;
	}
	public String getUserPwd() {
		return userPwd;
	}
	public void setUserPwd(String userPwd) {
		this.userPwd = userPwd;
	}
	public String getPhoto() {
		return photo;
	}
	public void setPhoto(String photo) {
		this.photo = photo;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public Delegation getDelegation() {
		return delegation;
	}
	public void setDelegation(Delegation delegation) {
		this.delegation = delegation;
	}
	@Override
	public String toString() {
		return "User [userId=" + userId + ", userLoginName=" + userLoginName + ", userTel=" + userTel + ", userPwd="
				+ userPwd + ", photo=" + photo + ", userName=" + userName + ", delegation=" + delegation + "]";
	}
	
	
}

2、代表团实体

package com.qf.meeting.pojo;
import java.io.Serializable;
import java.util.List;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
public class Delegation implements Serializable{
	private final static Logger LOG = LogManager.getLogger(Delegation.class);

	private Integer delegationId;
	
	private String delegationName;
	
	private List users;

	public Delegation() {
		super();
		// TODO Auto-generated constructor stub
	}

	public Delegation(Integer delegationId, String delegationName, List users) {
		super();
		this.delegationId = delegationId;
		this.delegationName = delegationName;
		this.users = users;
	}

	public Integer getDelegationId() {
		return delegationId;
	}

	public void setDelegationId(Integer delegationId) {
		this.delegationId = delegationId;
	}

	public String getDelegationName() {
		return delegationName;
	}

	public void setDelegationName(String delegationName) {
		this.delegationName = delegationName;
	}

	public List getUsers() {
		return users;
	}

	public void setUsers(List users) {
		this.users = users;
	}

	@Override
	public String toString() {
		return "Delegation [delegationId=" + delegationId + ", delegationName=" + delegationName + ", users=" + users
				+ "]";
	}

}

3、xml文件




	
		
		
		
			
			
			
			
			
		
	

	

4、查询结果

[{"delegationId":1,"delegationName":null,"users":[{"userId":1,"userLoginName":"zz","userTel":"********","userPwd":"123456","photo":"zz.jpg","userName":"zzz","delegation":null,"staffs":null},{"userId":2,"userLoginName":"zz","userTel":"***********","userPwd":"123456","photo":"zz.jpg","userName":"zz","delegation":null,"staffs":null}]}]

你可能感兴趣的:(Mybatis)