id:一般就是唯一的标识,和对应的xxxMapper.java的接口方法名对应
parameterType:传给此语句的参数的完整类名或别名
resultType:语句返回值类型的整类名或别名。注意,如果是集合,那么这里填写的是集合的项的整类名或别名,而不是集合本身的类名。(resultType 与resultMap 不能并用)
resultMap:引用的外部resultMap 名。结果集映射是MyBatis 中最强大的特性。许多复杂的映射都可以轻松解决。(resultType 与resultMap 不能并用)
案例:
List<Custumer> queryCustomerBlackListByStatusAndisActive(
@Param
(value =
"status"
) Integer status,
@Param
(value =
"isActive"
)Integer isActive);
<
select
id
="queryCustomerBlackListByStatusAndisActive"
resultType
="com.caocao.core.model.Custumer"
>
SELECT
<
include
refid
="CustumerResultMap_Base_Column_List"
/>
FROM tsp_caocao_customer_blacklist b
INNER JOIN tsp_caocao_custumer c ON b._deviceid = c._driver_deviceid AND c._status= 1
WHERE b._status = #{status,jdbcType=INTEGER} AND b._isActive = #{isActive,jdbcType=INTEGER}
</
select
>
该案例并没有使用
parameterType,而参数是如何传进来的?
解答:使用注解
@Param
。
上述例子
@Param
(value =
"status"
) Integer status 中的value需要和#{status,jdbcType=INTEGER}中的status名字一致
另一种方式:采用
parameterType
本人一般情况都是使用完整类名
List<Custumer> queryCustomerBlackListByStatusAndisActive(Custumer custumer);
<
select
id
="queryCustomerBlackListByStatusAndisActive"
parameterType
="com.caocao.core.model.Customer"
resultType
="com.caocao.core.model.Custumer"
>
SELECT
<
include
refid
="CustumerResultMap_Base_Column_List"
/>
FROM tsp_caocao_customer_blacklist b
INNER JOIN tsp_caocao_custumer c ON b._deviceid = c._driver_deviceid AND c._status= 1
WHERE b._status = #{status,jdbcType=INTEGER} AND b._isActive = #{isActive,jdbcType=INTEGER}
</
select
>
这时参数的名称需要和
parameterType
中所对应的类属性名称保持一致。
同时讲解一下
resultType,对于产生的结果一般对应的字段名称(或者字段别名)需要和resultType中的类属性名称保持一致,不然不会映射到对应属性上。