1:写sql语句时起别名
<select id="findById" resultType="com.smy.mybatis.entity.Emp">
select id,user_name username,salary,dept_id deptId from emp where id = #{id}
</select>
2:在mybatis的全局配置文件中开启驼峰命名规则
sql表中前一个单词和后一个单词中间必须是_;例:user_name 这种
<settings>
<setting name="mapUnderscoreToCamelCase" value="true"></setting>
</settings>
3:在Mapper映射文件中使用resultMap来定义映射规则/起别名
<resultMap id="empMap" type="com.smy.mybatis.entity.Emp">
<id column="id" property="id"></id>
<result column="user_name" property="username"></result>
<result column="salary" property="salary"></result>
<result column="dept_id" property="deptId"></result>
</resultMap>