mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
commit
c5fb1fbea8
@ -194,6 +194,19 @@ public interface BaseMapper<T> {
|
|||||||
|
|
||||||
// === 删(delete) ===
|
// === 删(delete) ===
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据实体主键来删除数据。
|
||||||
|
*
|
||||||
|
* @param entity 实体对象,必须包含有主键
|
||||||
|
* @return 受影响的行数
|
||||||
|
*/
|
||||||
|
default int delete( T entity){
|
||||||
|
FlexAssert.notNull(entity, "entity can not be null");
|
||||||
|
TableInfo tableInfo = TableInfoFactory.ofEntityClass(entity.getClass());
|
||||||
|
Object[] pkArgs = tableInfo.buildPkSqlArgs(entity);
|
||||||
|
return deleteById(pkArgs);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据主键删除数据。如果是多个主键的情况下,需要传入数组,例如:{@code new Integer[]{100,101}}。
|
* 根据主键删除数据。如果是多个主键的情况下,需要传入数组,例如:{@code new Integer[]{100,101}}。
|
||||||
*
|
*
|
||||||
@ -368,6 +381,19 @@ public interface BaseMapper<T> {
|
|||||||
|
|
||||||
// === 查(select) ===
|
// === 查(select) ===
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据实体主键查询数据。
|
||||||
|
*
|
||||||
|
* @param entity 实体对象,必须包含有主键
|
||||||
|
* @return 实体类数据
|
||||||
|
*/
|
||||||
|
default T selectOneByEntity(T entity){
|
||||||
|
FlexAssert.notNull(entity, "entity can not be null");
|
||||||
|
TableInfo tableInfo = TableInfoFactory.ofEntityClass(entity.getClass());
|
||||||
|
Object[] pkArgs = tableInfo.buildPkSqlArgs(entity);
|
||||||
|
return selectOneById(pkArgs);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据主键查询数据。
|
* 根据主键查询数据。
|
||||||
*
|
*
|
||||||
|
|||||||
@ -151,6 +151,16 @@ public interface IService<T> {
|
|||||||
return remove(query().where(condition));
|
return remove(query().where(condition));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>根据实体主键删除数据。
|
||||||
|
*
|
||||||
|
* @param entity 实体类对象
|
||||||
|
* @return {@code true} 删除成功,{@code false} 删除失败。
|
||||||
|
*/
|
||||||
|
default boolean removeById(T entity) {
|
||||||
|
return SqlUtil.toBool(getMapper().delete(entity));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>根据数据主键删除数据。
|
* <p>根据数据主键删除数据。
|
||||||
*
|
*
|
||||||
@ -284,6 +294,26 @@ public interface IService<T> {
|
|||||||
return getMapper().selectOneById(id);
|
return getMapper().selectOneById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>根据实体主键查询数据。
|
||||||
|
*
|
||||||
|
* @param entity 实体对象,必须包含有主键
|
||||||
|
* @return 查询结果数据
|
||||||
|
*/
|
||||||
|
default T getOneByEntity(T entity) {
|
||||||
|
return getMapper().selectOneByEntity(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>根据实体主键查询数据。
|
||||||
|
*
|
||||||
|
* @param entity 实体对象,必须包含有主键
|
||||||
|
* @return 查询结果数据
|
||||||
|
* @apiNote 该方法会将查询结果封装为 {@link Optional} 类进行返回,方便链式操作。
|
||||||
|
*/
|
||||||
|
default Optional<T> getByEntityOpt(T entity) {
|
||||||
|
return Optional.ofNullable(getOneByEntity(entity));
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* <p>根据数据主键查询一条数据。
|
* <p>根据数据主键查询一条数据。
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user