mybatis中自定义1对1的resultMap

1·首先是javabean:

public class jeweryCartTbl {
    private String id;

    private String memberid;

    private String jeweryAllId;

    private String type;

    private Integer count;

    private String ischeck;

    private Date createTime;

    private Date lastmodifyTime;

    private String categoryid;
    
    private JeweryTbl jeweryTbl;  <span style="color:#FF0000;"><strong>//这个是1对1的属性值</strong></span>
    
    public jeweryTbl getjeweryTbl() {
		return jeweryTbl;
	}

	public void setjeweryTbl(jeweryTbl jeweryTbl) {
		this.jeweryTbl = jeweryTbl;
	}

	public String getId() {
        return id;
    }

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

    public String getMemberid() {
        return memberid;
    }

    public void setMemberid(String memberid) {
        this.memberid = memberid == null ? null : memberid.trim();
    }

    public String getjeweryAllId() {
        return jeweryAllId;
    }

    public void setjeweryAllId(String jeweryAllId) {
        this.jeweryAllId = jeweryAllId == null ? null : jeweryAllId.trim();
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type == null ? null : type.trim();
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public String getIscheck() {
        return ischeck;
    }

    public void setIscheck(String ischeck) {
        this.ischeck = ischeck == null ? null : ischeck.trim();
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getLastmodifyTime() {
        return lastmodifyTime;
    }

    public void setLastmodifyTime(Date lastmodifyTime) {
        this.lastmodifyTime = lastmodifyTime;
    }

    public String getCategoryid() {
        return categoryid;
    }

    public void setCategoryid(String categoryid) {
        this.categoryid = categoryid == null ? null : categoryid.trim();
    }
}

2·编写resultMap

<span style="color:#FF0000;"><strong>//编写对应的resultMap
//1·首先property与javabean中的属性一致
//2·如果两个关联的有相同的属性 例如:id 设置成不同的属性</strong></span>
<resultMap id="BaseResultMap_1" type="com.model.jeweryCartTbl" >
    <id column="id" property="id" jdbcType="VARCHAR" />
    <result column="memberid" property="memberid" jdbcType="VARCHAR" />
    <result column="jewery_all_id" property="jeweryAllId" jdbcType="VARCHAR" />
    <result column="type" property="type" jdbcType="VARCHAR" />
    <result column="count" property="count" jdbcType="INTEGER" />
    <result column="ischeck" property="ischeck" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="lastmodify_time" property="lastmodifyTime" jdbcType="TIMESTAMP" />
    <result column="categoryid" property="categoryid" jdbcType="VARCHAR" />
    <association property="jeweryTbl" javaType="com.model.jeweryTbl"> 
    	<id <span style="color:#FF0000;"><strong>column="jeweryid"</strong></span> property="id" jdbcType="VARCHAR" />
	    <result column="name" property="name" jdbcType="VARCHAR" />
	    <result column="price" property="price" jdbcType="DECIMAL" />
    </association>
  </resultMap>

3·调用:

  //相同的属性定义重命名
  //如果不设置不同名字。相同的属性值会显示一个值(会覆盖)
  <select id="findCheckedCartByMember" resultMap="BaseResultMap_1">
    select dct.*,dt.price,<span style="color:#FF0000;"><strong>dt.id as jeweryid</strong></span>
    from jewery_cart_tbl dct
    left join jewery_category_value_tbl dcvt
    on dct.jewery_all_id = dcvt.id
	left join jewery_tbl dt
	on dcvt.jewery_all_id = dt.id
    where dct.ischeck = '1' 
	and dt.is_sale = '1'
    <if test="memberid != null">
    	and dct.memberid = #{memberid,jdbcType=VARCHAR}
    </if>
  </select>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值