resultType是自动封装的,当resultType满足不了时:
1.驼峰命名法 2. resultMap
resultMap 自定义结果集 强大且重要
关闭驼峰命名法法测试
public Employee getEmpById(Integer id);
<!-- 自定义某个javaBean的封装规则
type:自定义规则的java类型
id:唯一方便引用
-->
<resultMap id="myEmp" type="com.stayreal.mybatis.Employee">
<!-- 定义主键封装规则-->
<id column="id" property="id"/>
<!-- 定义普通列的封装规则,不指定的会自动封装,但推荐全部写出-->
<result column="last_name" property="lastName"/>
<result column="email" property="email"/>
<result column="gender" property="gender"/>
</resultMap>
<!-- public Employee getEmpById(Integer id);-->
<!-- resultMap:自定义结果集映射规则-->
<select id="getEmpById" resultMap="myEmp">
select * from tbl_employee where id = #{id}
</select>
EmployeeMapperPlus mapper = session.getMapper(EmployeeMapperPlus.class);
Employee employee = mapper.getEmpById(1);
System.out.println(employee.toString());