1. 返回resultType
1.1 如果返回的是一个集合,要写集合中元素的类型
<!-- lastName=%e% -->
<select id="getEmpsByLastNameLike" resultType="xxx.Employee">
select * from employee where last_anme like #{lastName}
</select>
public List<Employee> getEmpsByLastNameLike(String lastName);
1.2 返回一条记录的map,key是列名,value是值
<!-- lastName=%e% -->
<select id="getEmpByIdReturnMap" resultType="map">
select * from employee where last_anme like #{lastName}
</select>
public Map<String, String> getEmpByIdReturnMap(String lastName);
1.3 返回一条记录的map,key是主键,值是整条记录对象
<select id="xxx" resultType="....Employee">
select * from employee where last_name like #{lastName}
</select>
@MapKey("id") //指定键值
public Map<Integer, Employee> getEmpsByLastNameReturnMap(String lastName);
或
@MapKey("lastName") //指定键值
public Map<String, Employee> getEmpsByLastNameReturnMap(String lastName);
2. 返回resultMap
2.1 自动映射
开启自动映射
<setting name="autoMappingBehavior" value="" /> <!--默认PARTIAL-->
唯一要求是列名与javaBean属性名一致
value=“null” 取消自动映射
<setting name="mapUnderscoreToCamelCase" value="true" /> <!--开启驼峰命名-->
2.2 自定义resultMap 结果集映射规则:
<resultMap type="...Employee" id="方便引用">
<!--定义主键底层有优化-->
<id column