在resultMap节点中,id表示哪个字段代表这主键,result节点定义了普通的映射关系,这里的property表示JavaBean中的属性名称,column表示数据库中的字段名称,javaType代表JavaBean中该属性的类型,jdbcType则表示数据库中该字段的类型,
<resultMap id="userMap" type="org.sang.bean.User">
<id property="id" column="id" javaType="long" jdbcType="NUMERIC"/>
<result property="userName" column="user_name" javaType="string" jdbcType="VARCHAR"/>
<result property="password" column="password" javaType="string" jdbcType="VARCHAR"/>
<result property="address" column="address" javaType="string" jdbcType="VARCHAR"/>
</resultMap>
只需要在select查询的时候指定resultMap即可
<select id="getUser" resultMap="userMap" parameterType="Long">
select * from user2 where id = #{id}
</select>