MyBatis_select_レコードパッケージmap


EmployeeMapper.javaでの書き方:
// map;key , 
    public Map<String, Object> getEmpByIdReturnMap(Integer id);

方法:

    <select id="getEmpByIdReturnMap" resultType="map">
        select * from tbl_employee where id=#{id}
    select>

テスト:
EmployeeMapper mapper = openSession.getMapper(EmployeeMapper.class);
Map map = mapper.getEmpByIdReturnMap(1);
System.out.println(map);

これでEmployeeMapper.xmlをパッケージしました
複数のレコードのmapを返したい場合は、mapにメソッドを書きます.
    // mapMap<Integer,Employee>: , javaBean
    //@MapKey: mybatis map map key, Map key @MapKey("?") 
    @MapKey("id")
    public Map<Integer, Employee> getEmpByLastNameLikeReturnMap(String lastName);

方法:
    
    <select id="getEmpByLastNameLikeReturnMap" resultType="com.atguigu.mybatis.bean.Employee">
        select * from tbl_employee where last_name like #{lastName}
    select>

テスト:
EmployeeMapper mapper = openSession.getMapper(EmployeeMapper.class);
Map map = mapper.getEmpByLastNameLikeReturnMap("%r%");
System.out.println(map);