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<User> users;
public Delegation() {
super();
// TODO Auto-generated constructor stub
}
public Delegation(Integer delegationId, String delegationName, List<User> 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<User> getUsers() {
return users;
}
public void setUsers(List<User> users) {
this.users = users;
}
@Override
public String toString() {
return "Delegation [delegationId=" + delegationId + ", delegationName=" + delegationName + ", users=" + users
+ "]";
}
}
3、xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.qf.meeting.mapper.DelegationMapper">
<resultMap type="com.qf.meeting.pojo.Delegation" id="delegationMap">
<id property="delegationId" column="delegationId"/>
<result property="delegationName" column="delegationIdName"/>
<collection property="users" column="uId" autoMapping="true" ofType="com.qf.meeting.pojo.User">
<id property="userId" column="userId"/>
<result property="userName" column="userName"/>
<result property="userTel" column="userTel"/>
<result property="userLoginName" column="userLoginName"/>
<result property="userLoginName" column="userLoginName"/>
</collection>
</resultMap>
<select id="fingAll" resultMap="delegationMap">
select * from t_delegation d,t_user u where d.delegationId = u.delegationId;
</select>
</mapper>
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}]}]