Java源码示例:org.apache.ibatis.annotations.MapKey
示例1
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;
}
示例2
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;
}
示例3
@Select("select id, name from users")
@MapKey("id")
Map<Integer, User<String>> getAMapOfUsers();
示例4
@Select("select * from person")
@MapKey("id")
Map<Integer, Person> selectAsMap();
示例5
@Select("select id, name from users")
@MapKey("id")
Map<Integer, User<String>> getAMapOfUsers();
示例6
@Select("select * from person")
@MapKey("id")
Map<Integer, Person> selectAsMap();