MyBatis中ResultMap的用法

1.其中com.redstone.seehot.bean.AuthRole为某个实体类

<?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.redstone.seehot.mappers.AuthRoleMapper" >

    <resultMap id="BaseResultMap" type="com.redstone.seehot.bean.AuthRole" >
        <id column="id" property="id" jdbcType="BIGINT" />
        <result column="role" property="role" jdbcType="VARCHAR" />
        <result column="name" property="name" jdbcType="VARCHAR" />
        <result column="description" property="description" jdbcType="VARCHAR" />
        <result column="createtime" property="createtime" jdbcType="TIMESTAMP" />
        <result column="updatetime" property="updatetime" jdbcType="TIMESTAMP" />
    </resultMap>

    <select id="selectAll" resultMap="BaseResultMap">
        select
             id, role, name, description, createtime, updatetime
        from auth_role
        order by id asc
    </select>

</mapper>

2.将实体Bank作为BankCard的属性映射

 <resultMap type="BankCard" id="BankCardMapping">
        <id property="id" column="id"/>
        <result property="createTime" column="createTime"/>
        <result property="updateTime" column="updateTime"/>
        <result property="number" column="number"/>
        <result property="cardholder" column="cardholder"/>
        <result property="idcard" column="idcard"/>
        <result property="bankId" column="bankId"/>
        <result property="makerId" column="makerId"/>
        <result property="isBind" column="isBind"/>
        <result property="idcardBlur" column="idcardBlur"/>
        <result property="numberBlur" column="numberBlur"/>
        <association property="bank" javaType="Bank">
            <result property="id" column="bank_id"/>
            <result property="name" column="bank_name"/>
            <result property="code" column="bank_code"/>
            <result property="logo" column="bank_logo"/>
            <result property="bgImg" column="bank_bgImg"/>
            <result property="bgColor" column="bank_bgColor"/>
            <result property="url" column="bank_url"/>
            <result property="mobile" column="bank_mobile"/>
            <result property="isShow" column="bank_isShow"/>
        </association>
    </resultMap>

<select id="getUseCard" parameterType="Integer" resultMap="BankCardMapping">
        SELECT
          bankCard.*,
          bank.id bank_id,
          bank.name bank_name,
          bank.code bank_code,
          bank.logo bank_logo,
          bank.bgImg bank_bgImg,
          bank.bgColor bank_bgColor,
          bank.url bank_url,
          bank.mobile bank_mobile,
          bank.isShow bank_isShow
        FROM bankCard
            LEFT JOIN bank bank
            ON bankCard.bankId = bank.id
        WHERE
            bankCard.isBind = 1
          AND
            bankCard.makerId = #{makerId}
    </select>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值