[简单写法]Mybatis中collection和association的使用区别

目录

直接截图上代码截图:

返回结果JSON:

代码:


简单的一种写法,代码阅读更方便

直接截图上代码截图:

返回的结果JSON:

 

代码:

	<resultMap id="DetailResultMap" type="com.ruoyi.aftersale.api.vo.MyRcecordDetail">
        <id column="id" property="id" />
        <result column="order_num" property="orderNum" />
        <result column="descs" property="content" />
		<result column="create_time" property="createTime" />
        <result column="status" property="status" />
       	<association  column="id" property="pingjia" select="queryPingJia" />		 
        <collection   column="id" property="history" select="queryHistory" />
    </resultMap>
 
	<select id="detail" resultMap="DetailResultMap">
		SELECT
			a.id,a.order_num,a.descs,a.create_time,a.`status`
		 FROM
			sh_record a
		WHERE a.id= #{id}
	</select>
	
	<select id="queryHistory"  resultType="com.ruoyi.aftersale.api.vo.HistoryVO">
		SELECT
			id hid,
			descs content,
			create_time htime 
		FROM
			sh_record_history 
		WHERE
			record_id = #{id}
	</select>
	
	<select id="queryPingJia"  resultType="com.ruoyi.aftersale.api.vo.PingjiaVO">
			SELECT
				id pid,
				score,
				content,
				deal_time timeLevel 
			FROM
				sh_pingjia 
			WHERE
				record_id = #{id}
		</select>
@Data
@AllArgsConstructor
@NoArgsConstructor
public class MyRcecordDetail {

	Integer id;
	String orderNum;
	String content;
	String createTime;
	Integer status;
	RcordTypeEnum statusEnum ;
	List<HistoryVO> history;
  	
	PingjiaVO pingjia;
	
	
	
	private void setStatus(Integer status) {
		this.status = status;

		statusEnum = RcordTypeEnum.getEnum(status);
	}
}





@AllArgsConstructor
@NoArgsConstructor
@Data
public class HistoryVO {

	Integer hid;
	String descs;
	Date htime;
}




@Data
@AllArgsConstructor
@NoArgsConstructor
public class PingjiaVO {
	Integer pId;
	Long recordId;

	Long score;
	String content;
	String timeLevel;
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值