mybatis自定义结果集映射规则

当数据库查询的字段和POJO中的属性名不一致时,可以自定义结果集。使用resultMap

 <!--type 指定返回的指定类型的全类名,id是该resultMap的唯一标识-->
<resultMap type="com.neuedu.bean.tbl_employee" id="findTblEmployeeByIdMap">
<!-- id 标签 用于指定该类中主键属性,
    resultMap用于类的普通属性
    column用于指定数据库中获取的字段,如果字段是有别名,就写别名
    property用于指定POJO中属性。
--> <id column="id" property="id" /> <result column="email" property="email" /> <result column="gender" property="gender" /> <result column="user_name" property="userName" /> <result column="d_id" property="dId"/> </resultMap>
<!-- 这里不再使用resultType,而是使用resultMap,resultMap指定我们上面创建的resultMap的id-->
<
select id="selectDepartment" resultType="findTblEmployeeByIdMap">
    select * from tbl_dept where id=#{id}
 
</select>
原文地址:https://www.cnblogs.com/xuesheng/p/7481390.html