mybatis中的resulitMap配置

来源:互联网 发布:失踪的青蛙少年知乎 编辑:程序博客网 时间:2024/06/06 06:48
首先我们给resultMap取了一个id,这个id是resultMap的唯一标识符,我们在后面引用这个resultMap的时候就是通过这个id来引用,然后还定义了type属性,type属性指明了这个resultMap它对应的是哪个JavaBean。 

在resultMap节点中,id表示哪个字段代表这主键,result节点定义了普通的映射关系,这里的property表示JavaBean中的属性名称,column表示数据库中的字段名称,javaType代表JavaBean中该属性的类型,jdbcType则表示数据库中该字段的类型,

<resultMapid="userMap" type="org.sang.bean.User">

<idproperty="id" column="id" javaType="long" jdbcType="NUMERIC"/>

<resultproperty="userName" column="user_name" javaType="string" jdbcType="VARCHAR"/>

<resultproperty="password" column="password" javaType="string" jdbcType="VARCHAR"/>

<resultproperty="address" column="address" javaType="string" jdbcType="VARCHAR"/>

</resultMap>

只需要在select查询的时候指定resultMap即可

<select id="getUser" resultMap="userMap" parameterType="Long">
        select * from user2 where id = #{id}
    </select>




原创粉丝点击