Annotation Type Select


  • @Documented
    @Retention(RUNTIME)
    @Target(METHOD)
    @Repeatable(List.class)
    public @interface Select
    The annotation that specify an SQL for retrieving record(s).

    How to use:

    • Simple:
       public interface UserMapper {
         @Select("SELECT id, name FROM users WHERE id = #{id}")
         User selectById(int id);
       }
    • Dynamic SQL:
       public interface UserMapper {
         @Select({ "<script>", "select * from users", "where name = #{name}",
             "<if test=\"age != null\"> age = #{age} </if>", "</script>" })
         User select(@NotNull String name, @Nullable Integer age);
       }
    See Also:
    How to use Dynamic SQL
    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      java.lang.String[] value
      Returns an SQL for retrieving record(s).
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      boolean affectData
      Returns whether this select affects DB data.
      e.g.
      java.lang.String databaseId  
    • Element Detail

      • value

        java.lang.String[] value
        Returns an SQL for retrieving record(s).
        Returns:
        an SQL for retrieving record(s)
      • databaseId

        java.lang.String databaseId
        Returns:
        A database id that correspond this statement
        Since:
        3.5.5
        Default:
        ""
      • affectData

        boolean affectData
        Returns whether this select affects DB data.
        e.g. RETURNING of PostgreSQL or OUTPUT of MS SQL Server.
        Returns:
        true if this select affects DB data; false if otherwise
        Since:
        3.5.12
        Default:
        false