mybatiis discriminator + association

<?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.gxhc.system.system.mapper.SysCustomGroupExtendMapper" >
  <resultMap id="BaseResultMap" type="com.gxhc.system.system.table.entity.SysCustomGroup" >
    <id column="ID" property="id" jdbcType="VARCHAR" />
    <result column="Group_Name" property="groupName" jdbcType="VARCHAR" />
    <result column="Parent_ID" property="parentId" jdbcType="VARCHAR" />
    <result column="ID_Path" property="idPath" jdbcType="VARCHAR" />
    <result column="Obj_ID" property="objId" jdbcType="VARCHAR" />
    <result column="Obj_Type" property="objType" jdbcType="INTEGER" />
    <result column="Seq" property="seq" jdbcType="INTEGER" />
    
     <discriminator javaType="int" column="Obj_Type">
		   <case value="1" resultType="com.gxhc.system.system.dto.SysCustomGroupDto">
			   <association property="user" javaType="com.gxhc.system.system.table.entity.User">
				    <id property="id" column="user_id"/>
				    <result property="name" column="user_name"/>
				    <result property="idPath" column="user_idPath"/>
			  	</association>
		   </case>
		   <case value="2" resultType="com.gxhc.system.system.dto.SysCustomGroupDetpDto">
			   <association property="dept" javaType="com.gxhc.system.system.table.entity.Dept">
				    <id property="id" column="dept_id"/>
				    <result property="deptName" column="dept_deptName"/>
				    <result property="idPath" column="dept_idPath"/>
			  	</association>
		   </case>
	 </discriminator>
  </resultMap>
  
 
  
  <sql id="Example_Where_Clause" >
    <where >
      <foreach collection="oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  
  <sql id="Base_Column_List" >
    scg.ID, scg.Group_Name, scg.Parent_ID, scg.ID_Path, scg.Obj_ID, scg.Obj_Type, scg.Seq,su.id user_id,su.name user_name,su.id_path user_idPath,sd.id  dept_id,
    sd.dept_name dept_deptName,sd.id_path dept_idPath
  </sql>
  
  
  
  <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.gxhc.system.system.table.entity.SysCustomGroupExample" >
    select
    <if test="distinct" >
      distinct
    </if>
    <include refid="Base_Column_List" />
    from sys_custom_group scg
    LEFT JOIN sys_user su
    on scg.Obj_ID = su.id 
    LEFT JOIN sys_dept sd
    on sd.id = scg.Obj_ID
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null" >
      order by ${orderByClause}
      <if test="limitStart > -1" >
        limit ${limitStart} , ${limitEnd}
      </if>
    </if>
  </select>
  
  
  
  
  
   <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from sys_custom_group scg
    INNER JOIN sys_user su
    on scg.Obj_ID = su.id
    LEFT JOIN sys_dept sd
    on sd.id = scg.Obj_ID
    where scg.ID = #{id,jdbcType=VARCHAR}
  </select> 
  
  
 
</mapper>
package com.gxhc.system.system.table.entity;

import java.io.Serializable;

public class SysCustomGroup implements Serializable {
    private String id;

    private String groupName;

    private String parentId;

    private String idPath;

    private String objId;

    private Integer objType;

    private Integer seq;

    private static final long serialVersionUID = 1L;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id == null ? null : id.trim();
    }

    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName == null ? null : groupName.trim();
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId == null ? null : parentId.trim();
    }

    public String getIdPath() {
        return idPath;
    }

    public void setIdPath(String idPath) {
        this.idPath = idPath == null ? null : idPath.trim();
    }

    public String getObjId() {
        return objId;
    }

    public void setObjId(String objId) {
        this.objId = objId == null ? null : objId.trim();
    }

    public Integer getObjType() {
        return objType;
    }

    public void setObjType(Integer objType) {
        this.objType = objType;
    }

    public Integer getSeq() {
        return seq;
    }

    public void setSeq(Integer seq) {
        this.seq = seq;
    }

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        SysCustomGroup other = (SysCustomGroup) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
            && (this.getGroupName() == null ? other.getGroupName() == null : this.getGroupName().equals(other.getGroupName()))
            && (this.getParentId() == null ? other.getParentId() == null : this.getParentId().equals(other.getParentId()))
            && (this.getIdPath() == null ? other.getIdPath() == null : this.getIdPath().equals(other.getIdPath()))
            && (this.getObjId() == null ? other.getObjId() == null : this.getObjId().equals(other.getObjId()))
            && (this.getObjType() == null ? other.getObjType() == null : this.getObjType().equals(other.getObjType()))
            && (this.getSeq() == null ? other.getSeq() == null : this.getSeq().equals(other.getSeq()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getGroupName() == null) ? 0 : getGroupName().hashCode());
        result = prime * result + ((getParentId() == null) ? 0 : getParentId().hashCode());
        result = prime * result + ((getIdPath() == null) ? 0 : getIdPath().hashCode());
        result = prime * result + ((getObjId() == null) ? 0 : getObjId().hashCode());
        result = prime * result + ((getObjType() == null) ? 0 : getObjType().hashCode());
        result = prime * result + ((getSeq() == null) ? 0 : getSeq().hashCode());
        return result;
    }
}
package com.gxhc.system.system.dto;

import java.io.Serializable;

import com.gxhc.system.system.table.entity.Dept;
import com.gxhc.system.system.table.entity.SysCustomGroup;

public class SysCustomGroupDetpDto extends SysCustomGroup implements Serializable {

    private Dept dept;
    private static final long serialVersionUID = 1L;
	public Dept getDept() {
		return dept;
	}
	public void setDept(Dept dept) {
		this.dept = dept;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((dept == null) ? 0 : dept.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		SysCustomGroupDetpDto other = (SysCustomGroupDetpDto) obj;
		if (dept == null) {
			if (other.dept != null)
				return false;
		} else if (!dept.equals(other.dept))
			return false;
		return true;
	}
    

 
}
package com.gxhc.system.system.dto;

import java.io.Serializable;

import com.gxhc.system.system.table.entity.Dept;
import com.gxhc.system.system.table.entity.SysCustomGroup;
import com.gxhc.system.system.table.entity.User;

public class SysCustomGroupDto extends SysCustomGroup implements Serializable {
    private User user;
    private static final long serialVersionUID = 1L;
    

    public User getUser() {
		return user;
	}



	public void setUser(User user) {
		this.user = user;
	}



	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((user == null) ? 0 : user.hashCode());
		return result;
	}



	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		SysCustomGroupDto other = (SysCustomGroupDto) obj;
		if (user == null) {
			if (other.user != null)
				return false;
		} else if (!user.equals(other.user))
			return false;
		return true;
	}



	
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值