Package org.apache.ibatis.annotations
Annotation Type NamedResultMap
@Documented
@Retention(RUNTIME)
@Target(TYPE)
@Repeatable(NamedResultMaps.class)
public @interface NamedResultMap
Annotation for defining result maps that are not directly tied to select statements.
A named result map can be used to define a result map that can be reused with multiple statements. The named result map must be attached to a type (typically a mapper interface).
Multiple NamedResultMap annotations can be attached to a type.
Users of the annotation can declare any combination of property mappings, constructor arguments, and/or a type discriminator. At least one of the three must be declared.
How to use:
@NamedResultMap(id = UserMapper.userResultId, javaType = User.class, propertyMappings = {
@Result(property = "id", column = "id", id = true),
@Result(property = "name", column = "name"),
@Result(property = "email" column = "id", one = @One(select = "selectUserEmailById", fetchType = FetchType.LAZY)),
@Result(property = "telephoneNumbers" column = "id", many = @Many(select = "selectAllUserTelephoneNumberById", fetchType = FetchType.LAZY))
})
public interface UserMapper {
String userResultId = "userResult";
@Select("SELECT id, name FROM users WHERE id = #{id}")
@ResultMap(userResultId)
User selectById(int id);
@Select("SELECT id, name FROM users")
@ResultMap(userResultId)
List<User> selectAll();
}
- Since:
- 3.6.0
-
Element Details
-
id
String idReturns the result map id.- Returns:
- the result map id
-
javaType
Class<?> javaTypeReturns the Java type created with this result map.- Returns:
- the Java type that should be created with this result map
-
constructorArguments
Arg[] constructorArgumentsReturns mapping definitions for constructor arguments.- Returns:
- mapping definitions
- Default:
{}
-
propertyMappings
Result[] propertyMappingsReturns mapping definitions for properties.- Returns:
- mapping definitions
- Default:
{}
-
typeDiscriminator
TypeDiscriminator typeDiscriminatorReturns the type discriminator for this result map. The default is effectively null - meaning no type discriminator is used.- Returns:
- the type discriminator for this result map
- Default:
@org.apache.ibatis.annotations.TypeDiscriminator(column="--NULL TYPE DISCRIMINATOR--", cases={})
-