java.lang.Object
com.baomidou.mybatisplus.extension.toolkit.SqlHelper

public final class SqlHelper extends Object
SQL 辅助类
从以下版本开始:
2016-11-06
作者:
hubin
  • 字段概要

    字段
    修饰符和类型
    字段
    说明
    static org.apache.ibatis.session.SqlSessionFactory
    主要用于 service 和 ar
  • 构造器概要

    构造器
    构造器
    说明
     
  • 方法概要

    修饰符和类型
    方法
    说明
    static <T, R, M extends com.baomidou.mybatisplus.core.mapper.BaseMapper<T>>
    R
    execute(Class<T> entityClass, com.baomidou.mybatisplus.core.toolkit.support.SFunction<M,R> sFunction)
    通过entityClass获取BaseMapper,再传入lambda使用该mapper,本方法自动释放链接
    static <E> boolean
    executeBatch(Class<?> entityClass, org.apache.ibatis.logging.Log log, Collection<E> list, int batchSize, BiConsumer<org.apache.ibatis.session.SqlSession,E> consumer)
    static boolean
    executeBatch(Class<?> entityClass, org.apache.ibatis.logging.Log log, Consumer<org.apache.ibatis.session.SqlSession> consumer)
    已过时。
    static <E> boolean
    executeBatch(org.apache.ibatis.session.SqlSessionFactory sqlSessionFactory, org.apache.ibatis.logging.Log log, Collection<E> list, int batchSize, BiConsumer<org.apache.ibatis.session.SqlSession,E> consumer)
     
    static boolean
    executeBatch(org.apache.ibatis.session.SqlSessionFactory sqlSessionFactory, org.apache.ibatis.logging.Log log, Consumer<org.apache.ibatis.session.SqlSession> consumer)
     
    static <T, M extends com.baomidou.mybatisplus.core.mapper.BaseMapper<T>>
    M
    getMapper(Class<T> entityClass, org.apache.ibatis.session.SqlSession sqlSession)
    通过entityClass获取Mapper,记得要释放连接 例: SqlSession sqlSession = SqlHelper.sqlSession(entityClass); try { BaseMapper<User> userMapper = getMapper(User.class, sqlSession); } finally { sqlSession.close(); }
    static <E> E
    getObject(Supplier<org.apache.ibatis.logging.Log> supplier, List<E> list)
     
    static <E> E
    getObject(org.apache.ibatis.logging.Log log, List<E> list)
    从list中取第一条数据返回对应List中泛型的单个结果
    static String
    getSqlStatement(Class<?> mapper, com.baomidou.mybatisplus.core.enums.SqlMethod sqlMethod)
    获取mapperStatementId
    static boolean
    retBool(Integer result)
    判断数据库操作是否成功
    static boolean
    retBool(Long result)
    判断数据库操作是否成功
    static long
    retCount(Long result)
    返回SelectCount执行结果
    static <E> boolean
    saveOrUpdateBatch(Class<?> entityClass, Class<?> mapper, org.apache.ibatis.logging.Log log, Collection<E> list, int batchSize, BiPredicate<org.apache.ibatis.session.SqlSession,E> predicate, BiConsumer<org.apache.ibatis.session.SqlSession,E> consumer)
    static <E> boolean
    saveOrUpdateBatch(org.apache.ibatis.session.SqlSessionFactory sqlSessionFactory, Class<?> mapper, org.apache.ibatis.logging.Log log, Collection<E> list, int batchSize, BiPredicate<org.apache.ibatis.session.SqlSession,E> predicate, BiConsumer<org.apache.ibatis.session.SqlSession,E> consumer)
    批量更新或保存
    static org.apache.ibatis.session.SqlSession
    sqlSession(Class<?> clazz)
    已过时。
    3.5.3.2 尽量少用,后期取消打开session方法
    static org.apache.ibatis.session.SqlSession
    已过时。
    3.5.4
    static org.apache.ibatis.session.SqlSessionFactory
    已过时。
    3.5.3.2 尽量少用,后期取消此方法获取实例
    static com.baomidou.mybatisplus.core.metadata.TableInfo
    table(Class<?> clazz)
    获取TableInfo

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 字段详细资料

    • FACTORY

      public static org.apache.ibatis.session.SqlSessionFactory FACTORY
      主要用于 service 和 ar
  • 构造器详细资料

    • SqlHelper

      public SqlHelper()
  • 方法详细资料

    • sqlSessionBatch

      @Deprecated public static org.apache.ibatis.session.SqlSession sqlSessionBatch(Class<?> clazz)
      已过时。
      3.5.4
      批量操作 SqlSession
      参数:
      clazz - 实体类
      返回:
      SqlSession
    • sqlSessionFactory

      @Deprecated public static org.apache.ibatis.session.SqlSessionFactory sqlSessionFactory(Class<?> clazz)
      已过时。
      3.5.3.2 尽量少用,后期取消此方法获取实例
      获取SqlSessionFactory
      参数:
      clazz - 实体类
      返回:
      SqlSessionFactory
      从以下版本开始:
      3.3.0
    • sqlSession

      @Deprecated public static org.apache.ibatis.session.SqlSession sqlSession(Class<?> clazz)
      已过时。
      3.5.3.2 尽量少用,后期取消打开session方法
      获取Session
      参数:
      clazz - 实体类
      返回:
      SqlSession
    • table

      public static com.baomidou.mybatisplus.core.metadata.TableInfo table(Class<?> clazz)
      获取TableInfo
      参数:
      clazz - 对象类
      返回:
      TableInfo 对象表信息
    • retBool

      public static boolean retBool(Integer result)
      判断数据库操作是否成功
      参数:
      result - 数据库操作返回影响条数
      返回:
      boolean
    • retBool

      public static boolean retBool(Long result)
      判断数据库操作是否成功
      参数:
      result - 数据库操作返回影响条数
      返回:
      boolean
    • retCount

      public static long retCount(Long result)
      返回SelectCount执行结果
      参数:
      result - ignore
      返回:
      int
    • getObject

      public static <E> E getObject(org.apache.ibatis.logging.Log log, List<E> list)
      从list中取第一条数据返回对应List中泛型的单个结果
      类型参数:
      E - ignore
      参数:
      list - ignore
      返回:
      ignore
    • getObject

      public static <E> E getObject(Supplier<org.apache.ibatis.logging.Log> supplier, List<E> list)
      从以下版本开始:
      3.4.3
    • executeBatch

      @Deprecated public static boolean executeBatch(Class<?> entityClass, org.apache.ibatis.logging.Log log, Consumer<org.apache.ibatis.session.SqlSession> consumer)
      已过时。
      执行批量操作
      参数:
      entityClass - 实体
      log - 日志对象
      consumer - consumer
      返回:
      操作结果
      从以下版本开始:
      3.4.0
    • executeBatch

      public static boolean executeBatch(org.apache.ibatis.session.SqlSessionFactory sqlSessionFactory, org.apache.ibatis.logging.Log log, Consumer<org.apache.ibatis.session.SqlSession> consumer)
    • executeBatch

      @Deprecated public static <E> boolean executeBatch(Class<?> entityClass, org.apache.ibatis.logging.Log log, Collection<E> list, int batchSize, BiConsumer<org.apache.ibatis.session.SqlSession,E> consumer)
      执行批量操作
      类型参数:
      E - T
      参数:
      entityClass - 实体类
      log - 日志对象
      list - 数据集合
      batchSize - 批次大小
      consumer - consumer
      返回:
      操作结果
      从以下版本开始:
      3.4.0
    • executeBatch

      public static <E> boolean executeBatch(org.apache.ibatis.session.SqlSessionFactory sqlSessionFactory, org.apache.ibatis.logging.Log log, Collection<E> list, int batchSize, BiConsumer<org.apache.ibatis.session.SqlSession,E> consumer)
    • saveOrUpdateBatch

      @Deprecated public static <E> boolean saveOrUpdateBatch(Class<?> entityClass, Class<?> mapper, org.apache.ibatis.logging.Log log, Collection<E> list, int batchSize, BiPredicate<org.apache.ibatis.session.SqlSession,E> predicate, BiConsumer<org.apache.ibatis.session.SqlSession,E> consumer)
      批量更新或保存
      类型参数:
      E - E
      参数:
      entityClass - 实体
      log - 日志对象
      list - 数据集合
      batchSize - 批次大小
      predicate - predicate(新增条件) notNull
      consumer - consumer(更新处理) notNull
      返回:
      操作结果
      从以下版本开始:
      3.4.0
    • saveOrUpdateBatch

      public static <E> boolean saveOrUpdateBatch(org.apache.ibatis.session.SqlSessionFactory sqlSessionFactory, Class<?> mapper, org.apache.ibatis.logging.Log log, Collection<E> list, int batchSize, BiPredicate<org.apache.ibatis.session.SqlSession,E> predicate, BiConsumer<org.apache.ibatis.session.SqlSession,E> consumer)
      批量更新或保存
      类型参数:
      E - E
      参数:
      sqlSessionFactory - SqlSessionFactory
      log - 日志对象
      list - 数据集合
      batchSize - 批次大小
      predicate - predicate(新增条件) notNull
      consumer - consumer(更新处理) notNull
      返回:
      操作结果
      从以下版本开始:
      3.5.4
    • getSqlStatement

      public static String getSqlStatement(Class<?> mapper, com.baomidou.mybatisplus.core.enums.SqlMethod sqlMethod)
      获取mapperStatementId
      参数:
      sqlMethod - 方法名
      返回:
      命名id
      从以下版本开始:
      3.4.0
    • getMapper

      public static <T, M extends com.baomidou.mybatisplus.core.mapper.BaseMapper<T>> M getMapper(Class<T> entityClass, org.apache.ibatis.session.SqlSession sqlSession)
      通过entityClass获取Mapper,记得要释放连接 例: SqlSession sqlSession = SqlHelper.sqlSession(entityClass); try { BaseMapper<User> userMapper = getMapper(User.class, sqlSession); } finally { sqlSession.close(); }
      类型参数:
      T - 实体类型
      M - Mapper类型
      参数:
      entityClass - 实体
      返回:
      Mapper
    • execute

      public static <T, R, M extends com.baomidou.mybatisplus.core.mapper.BaseMapper<T>> R execute(Class<T> entityClass, com.baomidou.mybatisplus.core.toolkit.support.SFunction<M,R> sFunction)
      通过entityClass获取BaseMapper,再传入lambda使用该mapper,本方法自动释放链接
      类型参数:
      T - 实体类的类型
      R - 返回值类型
      M - Mapper类型
      参数:
      entityClass - 实体类
      sFunction - lambda操作,例如 m->m.selectList(wrapper)
      返回:
      返回lambda执行结果