使用Mybatis查询的数据如何返回为long类型

2022-06-26 11:25:29

1.使用ResultMap指定Long类型

在查询数据的那一块的Resultmap指定为你刚才定义的那个ResultMap

<resultMap id="ResultOfLongPersonId" type="java.lang.Long">
     <result column="person_id" property="personId" javaType="long"/>
 </resultMap>

<select id="getPhoneGroupPersonIdsByGroupId" resultMap="ResultOfLongPersonId">
       select person_id from phone_group_person
       where phone_group_id=#{phoneGroupId,jdbcType=BIGINT}
       and is_delete=0
</select>

2.直接在查询的时候定义ResultType="Long"

<select id="getPhoneGroupPersonIdsByGroupId" resultType="Long">
       select person_id from phone_group_person
       where phone_group_id=#{phoneGroupId,jdbcType=BIGINT}
       and is_delete=0
</select>


  • 作者:Offer都没有的渣渣
  • 原文链接:https://blog.csdn.net/qq_43386944/article/details/122438326
    更新时间:2022-06-26 11:25:29