![resultMap自定义某个javaBean的封装规则代码 resultMap自定义某个javaBean的封装规则代码](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
<?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">
<!--namespace:名称空间 -->
<mapper namespace="cn.bdqn.mybatis.dao.EmpMapperPlus"> <!--
自定义某个javaBean的封装规则
type:要自定义规则的javaBean类型
id:唯一标识,方便引用
-->
<resultMap type="cn.bdqn.mybatis.been.Emp" id="myEmp">
<!--
id定义主键会有底层优化
指定主键列的封装规则
column:指定哪一列
property:指定对应的javaBean属性
-->
<id column="id" property="id"/>
<!--定义普通列封装规则 -->
<result column="last_name" property="lastName"/>
<!-- 其他不指定的列会自动封装,但是建议,如果我们写了resultMap,我们就把所有列的映射都写上 -->
<result column="email" property="email"/>
<result column="gender" property="gender"/>
</resultMap> <!-- public Emp getEmpById(Integer id); -->
<!-- resultMap自定义结果集 resultType和resultMap只能二选一 -->
<select id="getEmpById" resultMap="myEmp">
select * from emp where id=#{id}
</select> </mapper>