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>