如果从数据库中查询出来的字段名与pojo类的属性值不一致,通过定义一个resultMap对列名和pojo的属性名之间做一个映射关系
<mapper namespace="cn.itcast.mybatis.mapper.UserMapper">
<!-- 定义resultMap
type:ResultMap最终映射的java对象类型,可以使用别名
id:resultMap的唯一标识
-->
<resultMap type="cn.itcast.mybatis.po.UserCustom" id="findByName">
<!-- id:映射主键 column:字段名 property:pojo类属性名 -->
<id column="_id" property="id"/>
<result column="_sex" property="sex"/>
<result column="_username" property="username"/>
<result column="_birhtday" property="birthday"/>
<result column="_address" property="address"/>
</resultMap>
<!-- 由于查询出来的字段与pojo类属性值不对应,通过resultMap属性映射 -->
<select id="findUserById" parameterType="java.lang.String" resultMap="findByName">
<!--从数据库中查询出来的字段名和pojo类的属性名不一致-->
select id _id,username _username, sex _sex,birthday _birthday,address _address from user where username like '${value}'
</select>
</mapper>
<!--public List<UserCustom> findUserById(String username) throws Exception;-->