1、修改 SQL,给查询字段重命名,如 将 user_id 重命名为 userId
select user_id as userId from table
2、MyBatis 的 XML 映射文件中,使用 <resultMap> 标签,定义数据库字段名与实体 bean 的属性字段名的映射关系
< select id="getUser" parameterType="int" resultMap="”UserMap”">
select * from user where user_id=#{id}
< /select>
< resultMap type=”User” id=”UserMap”>
<!–- id 标签映射主键字段 -–>
< id property=”id” column=user_id>
<!–- result 标签映射非主键字段,property 为实体 bean 属性名,column 为数据库表中字段名 -–>
< result property=“userName” column =”user_name”/>
< /reslutMap>
【Java面试题与答案】整理推荐