mybatis的三种数据库映射实体类的⽅法1.实体类中变量完全和数据库中的字段名对应
例如:DB:ur_id, 则实体类中成员变量也是ur_id记录英语
托管给mybatis,mybatis会把变量和字段名⼀⼀映射camel
武汉出国2.在l⾥配置ttings
<ttings>
<tting name="mapUnderscoreToCamelCa" value="true"/>
</ttings>
加上这个配置后,mybatis帮我们把数据库字段按驼峰命名传给对应实体类字段
db:ur_id => 实体类urId
这个配置要加在的最前⾯
3.在Mapper的配置⽂件⾥配置映射关系(字段多后,不建议⽤)
stamp是什么意思
例如:我的Mapper配置⽂件是,l,在lect前加上resultMap
polyfit
accurate是什么意思<resultMap id="tb_ur" type="ity.TbUr">
<id column="id" property="id"/>
<result column="ur_id" property="urID"/>
<result column="ur_name" property="urName"/>
</resultMap>
个性英文签名其中:
resultMap中 id="tb_ur" 表⽰对应的表
定语从句专项练习>hexatype="ity.TbUr"表⽰对应的实体类
id column="id" property="id" 第⼀个id表⽰主键,column="id" 表⽰表中id字段,property="id表⽰对应实体类的id变量result column="ur_id" property="urID" result表⽰映射,column表的,property实体类的
注意:
使⽤这种⽅式,Mapper配置⽂件中,lect的配置,resultType要改成resultMap
resultType=实体类的相对路径,resultMap=配置项resultMap⾥的id的值上⾯的例⼦就是resultMap="tb_ur"
>accountfor