欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

mybatis - 字段映射

程序员文章站 2022-04-23 15:53:58
...

就这么简单

--------------------------- 对象(类)映射 ---------------------------
<resultMap type="com.rl.model.person" id="BaseResultMap">
   <!-- 字段映射     id:唯一标示,给 resultType(返回参数)指定
         type:指定实体类地址  
         id列只有一个
         column:表的字段名
         property:实体类的属性名
    -->
   <id column="person_id" property="personId"/>
   <result column="name" property="name"/>
   <result column="gender" property="gender"/>
   <result column="person_addr" property="personAddr"/>
   <result column="birthday" property="birthday"/>
</resultMap>

<!-- 配置中映射下方             parameterType:后台传递的参数        resultMap:字段映射:指定上方Id --> 
<select id="selectPersonById" parameterType="java.lang.Integer" resultMap ="BaseResultMap">
      select * from person_test where id = #{id}
</select>