Annotation Type TypeDiscriminator


@Documented
@Retention(RUNTIME)
@Target(METHOD)
public @interface TypeDiscriminator
The annotation that be grouping conditional mapping definitions.

How to use:

 public interface UserMapper {
   @Select("SELECT id, name, type FROM users ORDER BY id")
   @TypeDiscriminator(
     column = "type",
     javaType = String.class,
     cases = {
       @Case(value = "1", type = PremiumUser.class),
       @Case(value = "2", type = GeneralUser.class),
       @Case(value = "3", type = TemporaryUser.class)
     }
   )
   List<User> selectAll();
 }
 
Author:
Clinton Begin
  • Required Element Summary

    Required Elements
    Modifier and Type Required Element Description
    Case[] cases
    Returns conditional mapping definitions.
    String column
    Returns the column name(column label) that hold conditional value.
  • Optional Element Summary

    Optional Elements
    Modifier and Type Optional Element Description
    Class<?> javaType
    Return the java type for conditional value.
    JdbcType jdbcType
    Return the jdbc type for column that hold conditional value.
    Class<? extends TypeHandler> typeHandler
    Returns the TypeHandler type for retrieving a column value from result set.
  • Element Details

    • column

      String column
      Returns the column name(column label) that hold conditional value.
      Returns:
      the column name(column label)
    • cases

      Case[] cases
      Returns conditional mapping definitions.
      Returns:
      conditional mapping definitions
    • javaType

      Class<?> javaType
      Return the java type for conditional value.
      Returns:
      the java type
      Default:
      void.class
    • jdbcType

      JdbcType jdbcType
      Return the jdbc type for column that hold conditional value.
      Returns:
      the jdbc type
      Default:
      UNDEFINED
    • typeHandler

      Class<? extends TypeHandler> typeHandler
      Returns the TypeHandler type for retrieving a column value from result set.
      Returns:
      the TypeHandler type
      Default:
      org.apache.ibatis.type.UnknownTypeHandler.class