解决方案
1.写sql语句时起别名
EmployeeMapper.xml
<!--
id属性:必须是接口中方法的方法名
resultType属性:必须是方法的返回值的全类名
-->
<select id="getEmployeeById" resultType="com.wenchang.mybatis.entities.Employee">
select id,last_name lastName,eamil,salary,dept_id deptId from employees where id = #{id}
</select>
2.在MyBatis的全局配置文件中开启驼峰式命名规则
mybatis-config.xml
<settings>
<!-- 开启驼峰命名规则,可以将数据库中下划线映射为驼峰命名
例如:last_name 可以映射为lastName
-->
<setting name="mapUnderscoreToCameLCase" value="true" />
</settings>
EmployeeMapper.xml
<!--
id属性:必须是接口中方法的方法名
resultType属性:必须是方法的返回值的全类名
-->
<select id="getEmployeeById" resultType="com.wenchang.mybatis.entities.Employee">
select * from employees where id = #{id}
</select>
3.在Mapper映射文件中使用resultMap来自定义映射规则
mybatis-config.xml
<!--
<settings>
<!-- 开启驼峰命名规则,可以将数据库中下划线映射为驼峰命名
例如:last_name 可以映射为lastName
-->
<setting name="mapUnderscoreToCameLCase" value="true" />
</settings>
-->
EmployeeMapper.xml
<!--
id属性:必须是接口中方法的方法名
resultType属性:必须是方法的返回值的全类名
-->
<select id="getEmployeeById" resultMap="myMap">
select * from emplyees where id = #{id}
</select>
<!--自定义高级映射>
<resultMap type="com.wenchang.mybatis.entities.Employee" id="myMap">
<!-- 映射主键-->
<id column="id" property="id"/>
<!-- 映射其他列-->
<result column="last_name" property="lastName"/>
<result column="eamil" property="email"/>
<result column="salary" property="salary"/>
<result column="dept_id" property="deptId"/>
</resultMap>