在项目中遇到当只查找返回表中某几个字段时,如果Mybatis中返回类型是实体的话,返回结果是这个实体的全部字段无法得到我们想要的某几个字段。
在Mybatis中把返回结果设置为Map即可,就可以返回我们想要的字段。
Mapper层:
Map queryClientInfo(@Param("orderSignId") Long orderSignId);
Mapper.xml层:
<select id="queryClientInfo" resultType="Map">
SELECT
organization_name AS organizationName,
organization_isli AS organizationIsli,
registration_time AS registrationTime,
certification_date AS certificationDate,
certification_type AS certificationType,
certification_status AS certificationStatus
FROM order_sign
WHERE order_sign_id=#{orderSignId}
</select>