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中的类属性名称保持一致,不然不会映射到对应属性上。
本文详细解析了MyBatis中的参数传递及结果映射机制,包括id、parameterType、resultType和resultMap等核心概念。并通过具体案例说明如何使用@Param注解和parameterType属性进行参数传递,并强调了resultType中字段与类属性名称的一致性。
1016

被折叠的 条评论
为什么被折叠?



