Annotation Type 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
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Returns the result map id.
    Returns the Java type created with this result map.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Arg[]
    Returns mapping definitions for constructor arguments.
    Returns mapping definitions for properties.
    Returns the type discriminator for this result map.
  • Element Details

    • id

      String id
      Returns the result map id.
      Returns:
      the result map id
    • javaType

      Class<?> javaType
      Returns the Java type created with this result map.
      Returns:
      the Java type that should be created with this result map
    • constructorArguments

      Arg[] constructorArguments
      Returns mapping definitions for constructor arguments.
      Returns:
      mapping definitions
      Default:
      {}
    • propertyMappings

      Result[] propertyMappings
      Returns mapping definitions for properties.
      Returns:
      mapping definitions
      Default:
      {}
    • typeDiscriminator

      TypeDiscriminator typeDiscriminator
      Returns 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={})