自动映射
autoMappingBehavior 指定 MyBatis 应如何自动映射列到字段或属性。
配置属性 | 含义 |
---|---|
NONE | 表示取消自动映射; |
PARTIAL | 只会自动映射没有定义嵌套结果集映射的结果集。 |
FULL | 会自动映射任意复杂的结果集(无论是否嵌套) |
查询结果与pojo字段保持一致,自动映射
<select id="selectUsers" resultType="map">
select id, username, hashedPassword
from some_table
where id = #{id}
</select>
或者
<select id="selectUsers" resultType="User">
select
user_id as "id",
user_name as "userName",
hashed_password as "hashedPassword"
from some_table
where id = #{id}
</select>
驼峰映射规则
mapUnderscoreToCamelCase 是否开启自动驼峰命名规则(camel case)映射,即从经典数据库列名 A_COLUMN 到经典 Java 属性名 aColumn 的类似映射。
<select id="selectUsers" resultType="User">
select
user_id,
user_name,
hashed_password
from some_table
where id = #{id}
</select>