接口 MapperManage
- 所有已知实现类:
MapperManageImpl
public interface MapperManage
对表数据进行正删改查,若要更新更复杂的sql,请使用mapper.xml进行编写
-
方法概要
修饰符和类型方法说明<T> QueryWrapper<T> createQuery(Class<T> resultClass, String sql) 返回查询条件,只能执行查询。<T> QueryWrapper<T> createQuery(String sql, Class<T> resultClass) 返回查询条件,只能执行查询。createUpdate(String sql) 返回更新条件,执行更新操作。intdeleteById(Class<?> entityClass, Object id) 根据id删除数据。intdeleteById(Object entity) 根据id删除数据<T,E> int deleteByIds(Class<T> entityClass, List<E> ids) 根据id批量删除。voidexecuteSqlScript(File scriptFile) 执行sql脚本,自动处于事务中执行,出现失败时全部回滚。voidexecuteSqlScript(String sqlScript) 执行sql脚本,自动处于事务中执行,出现失败时全部回滚。<T> booleanexistsById(Class<T> entityClass, Object id) 根据id判断实体对象是否存在<T> T获取mapper.xml对象的接口类代理int插入数据,空值也会插入int插入数据<T> intinsertBatch(List<T> list) 批量插入数据<T> List<T> 查询所有<T> TselectById(Class<T> entityClass, Object id) 根据id查询数据<T> StringselectTableSql(Class<T> entityClass) 获取实体对象的查询表sql:select id, username, password from t_userintupdateById(Object entity) 根据id更新实体intupdateById(Object entity, boolean updateNull) 根据id更新实体
-
方法详细资料
-
createQuery
返回查询条件,只能执行查询。 例子:QueryWrapper<UserEntity> query = mapperManage.createQuery( "select * from t_user where id>#{id}", UserEntity.class); query.addParam("id", 2); List<UserEntity> list = query.getList(); System.out.println(list);- 类型参数:
T- 接收查询结果类- 参数:
sql- mybatis 语法的sql,例如 select * from t_user where id=#{id}resultClass- 接收查询结果的类型- 返回:
- 查询包装
-
createQuery
返回查询条件,只能执行查询。 例子:QueryWrapper<UserEntity> query = mapperManage.createQuery( UserEntity.class, "select * from t_user where id>#{id}" ); query.addParam("id", 2); List<UserEntity> list = query.getList(); System.out.println(list);- 类型参数:
T- 接收查询结果类- 参数:
resultClass- 接收查询结果的类型sql- mybatis 语法的sql,例如 select * from t_user where id=#{id}- 返回:
- 查询包装
- 从以下版本开始:
- 1.0.6
-
createUpdate
返回更新条件,执行更新操作。例1 :
例2:UpadateWrapper update = mapperManage.createUpdate("update t_user set password=#{p} where id=#{id}"); update.addParam("p", System.currentTimeMillis()).addParam("id", 1); int execute = update.execute(); log.info("受影响行数: {}", execute);UpadateWrapper update = mapperManage.createUpdate("insert into t_user(id,username) values (2,#{un})"); update.addParam("un", "lk"); int execute = update.execute(); log.info("受影响行数: {}", execute);- 参数:
sql- mybatis 语法的sql,例如 update t_user set age=28 where id=#{id}- 返回:
- 更新包装对象
-
selectAll
查询所有- 类型参数:
T- 实体对象类- 参数:
entityClass- 实体对象类- 返回:
- 查询结果,不为空。无结果时返回空List
-
selectById
根据id查询数据- 类型参数:
T- 实体对象类- 参数:
entityClass- 实体对象类id- 主键id- 返回:
- 无结果时返回 null
-
existsById
根据id判断实体对象是否存在- 类型参数:
T- boolean- 参数:
entityClass- 实体对象类id- 主键id- 返回:
- true 存在; false 不存在
-
insert
插入数据,空值也会插入- 参数:
entity- 实体对象- 返回:
- 影响的行数
-
insert
插入数据- 参数:
entity- 实体对象insertNull- 是否插入空值,若为 false 生成的sql不带空值的列- 返回:
- 影响的行数
-
insertBatch
批量插入数据- 参数:
list- 实体对象列表- 返回:
- 影响的行数
-
updateById
根据id更新实体- 参数:
entity- 实体对象- 返回:
- 影响的行数
-
updateById
根据id更新实体- 参数:
entity- 实体对象updateNull- 是否更新空值,若为 false 生成的sql不带空值的列- 返回:
- 影响的行数
-
deleteById
根据id删除数据- 参数:
entity- 实体对象- 返回:
- 影响的行数
-
deleteById
根据id删除数据。注意,不会触发PreUpdate和PostUpdate注解方法- 参数:
entityClass- 实体对象类id- 主键id- 返回:
- 影响的行数
-
deleteByIds
根据id批量删除。注意,不会触发PreUpdate和PostUpdate注解方法- 参数:
entityClass- 实体对象类ids- id列表- 返回:
- 影响的行数
-
getMapper
获取mapper.xml对象的接口类代理- 类型参数:
T- mapper接口类- 参数:
type- mapper接口- 返回:
- mapper接口代理对象
-
selectTableSql
获取实体对象的查询表sql:select id, username, password from t_user- 参数:
entityClass- 实体对象类- 返回:
- select id, username, password from t_user
-
executeSqlScript
执行sql脚本,自动处于事务中执行,出现失败时全部回滚。- 参数:
sqlScript- sql脚本内容
-
executeSqlScript
执行sql脚本,自动处于事务中执行,出现失败时全部回滚。- 参数:
scriptFile- sql脚本文件
-