Interface MappedQuery<T>

Type Parameters:
T - 查询类型泛型
All Known Implementing Classes:
MappedQuery.Default

public interface MappedQuery<T>
查询映射
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static final class 
    MappedQuery默认实现
  • Method Summary

    Modifier and Type
    Method
    Description
    <C extends Collection<T>>
    C
    collection(C collection)
    查询为集合
    default T
    查询第一条数据,自行确保sql查询结果为一条记录
    first(T defaultValue)
    查询第一条数据,自行确保sql查询结果为一条记录
    查询为list
    default List<T>
    list(List<T> holder)
    查询为list
    static <T> MappedQuery<T>
    of(JdbcExecutor executor, String sql, List<?> params, RowMapper<T> rowMapper)
    创建查询映射
    查询为optional
    set()
    查询为set,默认使用LikedHashSet实现,保留原顺序
    default Set<T>
    set(Set<T> holder)
    查询为set
    default Stream<T>
    查询为stream
    stream(Integer estimatedSize)
    查询为stream
  • Method Details

    • of

      static <T> MappedQuery<T> of(JdbcExecutor executor, String sql, List<?> params, RowMapper<T> rowMapper)
      创建查询映射
      Type Parameters:
      T - 类型
      Parameters:
      executor - 执行器
      sql - SQL
      params - 参数
      rowMapper - 行映射
      Returns:
      查询映射
    • collection

      <C extends Collection<T>> C collection(C collection)
      查询为集合
      Type Parameters:
      C - 集合类型
      Parameters:
      collection - 集合
      Returns:
      结果(实际为传入的结合对象,填充了结果)
    • first

      T first(T defaultValue)
      查询第一条数据,自行确保sql查询结果为一条记录

      无结果行或第一行的值为 null 时返回 defaultValue; 若 defaultValue 也为 null,则按类型返回兜底值: 基本类型返回类型默认值,集合/Map/数组返回空对象.

      Parameters:
      defaultValue - 默认值
      Returns:
      结果
    • first

      default T first()
      查询第一条数据,自行确保sql查询结果为一条记录
      Returns:
      结果,无结果行时基本类型返回类型默认值,集合/Map/数组返回空对象
    • list

      default List<T> list(List<T> holder)
      查询为list
      Parameters:
      holder - 结果承载器,可根据需要设定类型和初始值,避免扩容
      Returns:
      结果
    • list

      List<T> list()
      查询为list
      Returns:
      结果
    • optional

      Optional<T> optional()
      查询为optional

      无结果行,或第一行的值为 null 时返回 Optional.empty().

      Returns:
      结果
    • set

      default Set<T> set(Set<T> holder)
      查询为set
      Parameters:
      holder - 结果承载器,可根据需要设定类型和初始值,避免扩容
      Returns:
      结果
    • set

      Set<T> set()
      查询为set,默认使用LikedHashSet实现,保留原顺序
      Returns:
      结果
    • stream

      default Stream<T> stream()
      查询为stream

      结果集读尽或遍历异常时会自动释放连接;短路操作(limit/findFirst/anyMatch 等) 不会读尽结果集,必须使用 try-with-resources 或显式 close 释放连接。

      Returns:
      结果
    • stream

      Stream<T> stream(Integer estimatedSize)
      查询为stream

      结果集读尽或遍历异常时会自动释放连接;短路操作(limit/findFirst/anyMatch 等) 不会读尽结果集,必须使用 try-with-resources 或显式 close 释放连接。

      Parameters:
      estimatedSize - 预估条数, 仅作为 stream 的 estimateSize 提示值
      Returns:
      结果