<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.geo.dao.UserMapper">
<!--resultMap将数据库中的列(字段名)和entity中属性的名字建立映射关联,id 这个resultMap的唯一标识,type表示要映射的实体-->
<resultMap id="userMap" type="com.geo.entity.SysUser">
<!--//主键可以这样使用,id 为了调高性能-->
<id property="id" column="id"/>
<!--其他的字段,property代表entity属性,column 代表数据库字段-->
<result property="userName" column="user_name"/>
<result property="userPassword" column="user_password"/>
<result property="userEmail" column="user_email"/>
<result property="userInfo" column="user_info"/>
</resultMap>
<!-- 返回类型使用resultMap,就是前面定义的resultMap-->
<select id="selectById" resultMap="userMap">
select * from sys_user where id =#{id}
</select>
<!-- 返回类型使用resulType,需要SQL中为所有列名和属性名不一致的列设置别名,但是驼峰式命名的属性可以和数据库里的下划线自动转换,设置mybatis的setting mapUnderscoreToCamelCase 的值为true 所以这里使用 select * -->
<select id="selectAll" resultType="com.geo.entity.SysUser">
select * from sys_user
</select>
<insert id="insert">
insert into sys_user(id,user_name,user_password,user_email,user_info)
values(#{id},#{userName},#{userPassword},#{userEmail},#{userInfo})
</insert>
</mapper>
namespace 必须配置成接口的全限定名。Mybatis内部就是通过这讲接口和mapepr.xml关联起来的。接口中方法和mapper.xml 中的id对应。否则会报错