其他分享
首页 > 其他分享> > mybatis的association 一对一单向关联

mybatis的association 一对一单向关联

作者:互联网

  01、基础类

public class VolIntegral extends BaseEntity
{
    private static final long serialVersionUID = 1L;
private Long inId;
@Excel(name = "志愿者id") private Long vtId; @Excel(name = "志愿者积分值") private Long inIntegralNum; private Volunteer volunteer; public Volunteer getVolunteer() { return volunteer; } public void setVolunteer(Volunteer volunteer) { this.volunteer = volunteer; } @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) .append("inId", getInId()) .append("vtName",getVtName()) .append("volunteer", getVolunteer()) .toString(); } }
  <!--selectVolIntegralListOverride   积分列表的接口重写-->
 <resultMap type="com.biaogan.system.domain.Volunteer" id="VolunteerMap">
        <id property="vtId" column="vt_id"/>
        <result property="vtName" column="vt_name"/>
        <result property="vtIntegralCount" column="vt_integral_count"/>
 </resultMap>
    <resultMap type="com.biaogan.system.domain.VolIntegral" id="VolIntegralMap">
        <id property="inId" column="in_id"/>
        <result property="vtId" column="in_vt_id"/>
        <result property="inIntegralNum" column="in_integral_num"/>
        <result property="inAccessStatus" column="in_access_status"/>
        <association property="volunteer" resultMap="com.biaogan.system.mapper.VolIntegralMapper.VolunteerMap"/>
    </resultMap>
   
    <select id="selectVolIntegralListOverride" parameterType="com.biaogan.system.domain.VolIntegral" resultMap="VolIntegralMap">
       select vt.vt_id as vtidcp ,vt.vt_name,vol.* from vol_integral  vol
            left join volunteer vt on vol.in_vt_id= vt.vt_id
        <where>
            <if test="vtId != null ">and in_vt_id = #{vtId}</if>
            <if test="vtName != null ">and vt.vt_name = #{vtName}</if>         ---此处的vtName是 volunteer表中的
            <if test="inIntegralNum != null ">and in_integral_num = #{inIntegralNum}</if>
            <if test="inAccessStatus != null ">and in_access_status = #{inAccessStatus}</if>
            <if test="createId != null ">and create_id = #{createId}</if>
            <if test="createUser != null  and createUser != ''">and create_user = #{createUser}</if>
            <if test="updateUser != null  and updateUser != ''">and update_user = #{updateUser}</if>
            <if test="updateId != null ">and update_id = #{updateId}</if>
        </where>
        ORDER BY create_time  Desc ,update_time Desc
    </select>

 

 02、原理讲解

 

标签:name,vol,单向,private,vt,mybatis,id,association,volunteer
来源: https://www.cnblogs.com/zhangzaizz/p/16643206.html