mybatis resulttype如果是集合情形不能是集合本身,那为何可以是map
map不也是集合吗,为什么resulttype不能写list,可以写map?
当是List时:
mapper 接口: List<Employee> getAllEmps();
SQL 映射文件:
<select id="getAllEmps" resultType="employee">
select * from t_employee
</select>
当查询结果为一条,且resulttype是map时:
mapper 接口:Map<String, Object> getEmpAsMapById(Integer id);
SQL 映射文件:
<select id="getEmpAsMapById" resultType="map">
select * from t_employee where id = #{id}
</select>