- 方法一:查询sql语句时起别名
- 方法二:mybatis的全局配置文件中开启驼峰命名规则
- mybatis-config.xml
- 可以将数据库中的下划线映射为驼峰命名
- 例如:last_name可以映射为lastName
<configuration>
<settings>
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
.....
</configuration>
- 方法三:在Mapper映射文件中使用resultMap来自定义映射规则 EmployeeMapper.xml
<!-- 自定义高级映射 -->
<resultMap type="com.atguigu.mybatis.entities.Employee" id="myMap">
<!-- 映射主键 -->
<id column="id" property="id"/>
<!-- 映射其他列 -->
<result column="last_name" property="lastName"/>
<result column="email" property="email"/>
<result column="salary" property="salary"/>
<result column="dept_id" property="deptId"/>
</resultMap>