类 SqlHelper
java.lang.Object
com.baomidou.mybatisplus.extension.toolkit.SqlHelper
SQL 辅助类
- 从以下版本开始:
- 2016-11-06
- 作者:
- hubin
-
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static <T,R, M extends com.baomidou.mybatisplus.core.mapper.BaseMapper<T>>
Rexecute(Class<T> entityClass, com.baomidou.mybatisplus.core.toolkit.support.SFunction<M, R> sFunction) 通过entityClass获取BaseMapper,再传入lambda使用该mapper,本方法自动释放链接static <E> booleanexecuteBatch(Class<?> entityClass, org.apache.ibatis.logging.Log log, Collection<E> list, int batchSize, BiConsumer<org.apache.ibatis.session.SqlSession, E> consumer) 已过时。static booleanexecuteBatch(Class<?> entityClass, org.apache.ibatis.logging.Log log, Consumer<org.apache.ibatis.session.SqlSession> consumer) 已过时。static <E> booleanexecuteBatch(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 booleanexecuteBatch(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通过entityClass获取Mapper,记得要释放连接 例:SqlSession sqlSession = SqlHelper.sqlSession(entityClass); try { BaseMapper<User> userMapper = getMapper(User.class, sqlSession); } finally { sqlSession.close(); }static <E> Estatic <E> E从list中取第一条数据返回对应List中泛型的单个结果static StringgetSqlStatement(Class<?> mapper, com.baomidou.mybatisplus.core.enums.SqlMethod sqlMethod) 获取mapperStatementIdstatic boolean判断数据库操作是否成功static boolean判断数据库操作是否成功static long返回SelectCount执行结果static <E> booleansaveOrUpdateBatch(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> booleansaveOrUpdateBatch(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.SqlSessionsqlSession(Class<?> clazz) 已过时。3.5.3.2 尽量少用,后期取消打开session方法static org.apache.ibatis.session.SqlSessionsqlSessionBatch(Class<?> clazz) 已过时。3.5.4static org.apache.ibatis.session.SqlSessionFactorysqlSessionFactory(Class<?> clazz) 已过时。3.5.3.2 尽量少用,后期取消此方法获取实例static com.baomidou.mybatisplus.core.metadata.TableInfo获取TableInfo
-
字段详细资料
-
FACTORY
public static org.apache.ibatis.session.SqlSessionFactory FACTORY主要用于 service 和 ar
-
-
构造器详细资料
-
SqlHelper
public SqlHelper()
-
-
方法详细资料
-
sqlSessionBatch
已过时。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
已过时。3.5.3.2 尽量少用,后期取消打开session方法获取Session- 参数:
clazz- 实体类- 返回:
- SqlSession
-
table
获取TableInfo- 参数:
clazz- 对象类- 返回:
- TableInfo 对象表信息
-
retBool
判断数据库操作是否成功- 参数:
result- 数据库操作返回影响条数- 返回:
- boolean
-
retBool
判断数据库操作是否成功- 参数:
result- 数据库操作返回影响条数- 返回:
- boolean
-
retCount
返回SelectCount执行结果- 参数:
result- ignore- 返回:
- int
-
getObject
从list中取第一条数据返回对应List中泛型的单个结果- 类型参数:
E- ignore- 参数:
list- ignore- 返回:
- ignore
-
getObject
- 从以下版本开始:
- 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(新增条件) notNullconsumer- 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- SqlSessionFactorylog- 日志对象list- 数据集合batchSize- 批次大小predicate- predicate(新增条件) notNullconsumer- 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, R executeM extends com.baomidou.mybatisplus.core.mapper.BaseMapper<T>> (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执行结果
-
executeBatch(SqlSessionFactory, Log, Collection, int, BiConsumer)