private String getMapKey(Method method) { String mapKey = null; if (Map.class.isAssignableFrom(method.getReturnType())) { final MapKey mapKeyAnnotation = method.getAnnotation(MapKey.class); if (mapKeyAnnotation != null) { mapKey = mapKeyAnnotation.value(); } } return mapKey; }
private String getMapKey(Method method) { String mapKey = null; if (Map.class.isAssignableFrom(method.getReturnType())) { //如果返回类型是map类型的,查看该method是否有MapKey注解。如果有这个注解,将这个注解的值作为map的key final MapKey mapKeyAnnotation = method.getAnnotation(MapKey.class); if (mapKeyAnnotation != null) { mapKey = mapKeyAnnotation.value(); } } return mapKey; }
@SelectProvider(type = StatementProvider.class, method = "provideSelect") @MapKey("id") Map<T, S> selectMap(S param);
@Select("select id, name from users") @MapKey("id") Map<Integer, User<String>> getAMapOfUsers();
@Select("select * from person") @MapKey("id") Map<Integer, Person> selectAsMap();
@SuppressWarnings("unchecked") @Override @MapKey("id") public <PK> Map<PK, T> findMap(PK... ids) { return getSqlSession().selectMap("findMap", ids, "id"); }
@SuppressWarnings("unchecked") @MapKey("id") <PK> Map<PK, T> findMap(PK... ids);