Mybatis映射配置文件Mapper.xml详解

1.概述:

MyBatis 的真正强大在于它的映射语句,也是它的魔力所在。

2.常用的属性

常用的几个属性:

select元素:代表查询,类似的还有updateinsertdelete

id:这个statement的唯一标示

parameterType:输入参数类型,可选参数,mybatis可以自动推断数据类型

resultType:查询结果类型,如果结果是集合,请写集合内元素类型!

resultMap:结果集映射,这个和resultType 只能存在1个,应对复杂的结果集。

 

3.insert语句实现ID回显

4.解决字段名与列名不一致的问题

方案1.驼峰命名法

<settings>
<!--开启驼峰命名法-->
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>

方案2.使用结果集映射resultMap 

前提要关闭驼峰命名法:

<setting name="mapUnderscoreToCamelCase" value="false"/></settings>

自动匹配 配置主键信息  普通字段不需要匹配(如果不符合驼峰命名法则要  自己配置不同的字段信息<result>标签 关闭驼峰)

<resultMap type="User" id="usersResultMap" autoMapping="true">
<id column="id" property="id" />
</resultMap>
<select id="loginParam" resultMap="usersResultMap">
select * from tb_user where user_name ='${username}' and password='${password}'
</select>
posted on 2018-03-05 11:14  lichangyun  阅读(618)  评论(0编辑  收藏  举报