使用columnPrefix别名区分所属哪个类的字段

今天在写一个关联表查询的时候出现的几个问题。

需要查出这个订单的所有状态,属于一对多的关系

//这个为查询的语句
 <select id="selectOrderByMap" parameterType="java.lang.String" resultMap="OrderLinkAudit">
        select
        ord.id,ord.ser_title,ord.org_name,ord.status,audit.content as audit_content,    audit.create_time as audit_create_time,audit.order_id as audit_order_id 
        from ser_order ord
        left join ser_order_audit audit on ord.id = audit.order_id
        <where>
            <if test="_parameter!= null">
                and ord.id = #{_parameter, jdbcType=VARCHAR}
            </if>
        </where>
        order by audit.create_time desc
    </select>


// 订单关联审核记录 
    <resultMap id="OrderLinkAudit" type="com.xx.xx.xx.xx.Order" extends="BaseResultMap">
        <collection property="auditList" columnPrefix="audit_"
                    ofType="com.xx.xx.xx.xx.OrderAudit">
            <id column="id" jdbcType="VARCHAR" property="id"/>
            <result column="order_id" jdbcType="VARCHAR" property="orderId"/>
            <result column="status" jdbcType="INTEGER" property="status"/>
            <result column="user_id" jdbcType="VARCHAR" property="userId"/>
            <result column="user_name" jdbcType="VARCHAR" property="userName"/>
            <result column="content" jdbcType="VARCHAR" property="content"/>
            <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        </collection>
    </resultMap>

不了解resultMap,所以在使用的时候出了差错。

resultMap:适合使用返回值是自定义实体类的情况。

resultType:适合使用返回值得数据类型是非自定义的,即jdk的提供的类型。

在想返回有相同字段content,create_time ,一开始没有用resultMap中定义的别名columnPrefix=”audit_”,导致直接覆盖了,前一个表的相同字段值。
columnPrefix:定义的别名用来区分是哪个类的字段,映射对应的属性,区分他们分别属于哪些类。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值