mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 17:18:24 +08:00
style: add Model javadoc.
This commit is contained in:
parent
26efb7cb66
commit
9e82a0ac12
@ -24,6 +24,8 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Active Record 模型。
|
||||
*
|
||||
* @param <T> 实体类类型
|
||||
* @author 王帅
|
||||
* @since 2023-07-24
|
||||
@ -33,38 +35,85 @@ public abstract class Model<T extends Model<T>>
|
||||
extends QueryModel<T>
|
||||
implements MapperModel<T> {
|
||||
|
||||
/**
|
||||
* 根据实体类构建的条件删除数据。
|
||||
*
|
||||
* @return {@code true} 删除成功,{@code false} 删除失败
|
||||
*/
|
||||
public boolean remove() {
|
||||
return SqlUtil.toBool(baseMapper().deleteByQuery(getQueryWrapper()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据实体类构建的条件更新数据(自动忽略 {@code null} 值)。
|
||||
*
|
||||
* @return {@code true} 更新成功,{@code false} 更新失败
|
||||
*/
|
||||
public boolean update() {
|
||||
return update(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据实体类构建的条件更新数据,并设置是否忽略 {@code null} 值。
|
||||
*
|
||||
* @param ignoreNulls 是否忽略 {@code null} 值
|
||||
* @return {@code true} 更新成功,{@code false} 更新失败
|
||||
*/
|
||||
public boolean update(boolean ignoreNulls) {
|
||||
return SqlUtil.toBool(baseMapper().updateByQuery((T) this, ignoreNulls, getQueryWrapper()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据实体类构建的条件查询数据数量。
|
||||
*
|
||||
* @return 数据数量
|
||||
*/
|
||||
public long count() {
|
||||
return baseMapper().selectCountByQuery(getQueryWrapper());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据实体类构建的条件判断数据是否存在。
|
||||
*
|
||||
* @return {@code true} 数据存在,{@code false} 数据不存在
|
||||
*/
|
||||
public boolean exists() {
|
||||
return SqlUtil.toBool(count());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据实体类构建的条件获取一条数据。
|
||||
*
|
||||
* @return 数据
|
||||
*/
|
||||
public T one() {
|
||||
return baseMapper().selectOneByQuery(getQueryWrapper());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据实体类构建的条件获取一条数据,并封装为 {@link Optional} 返回。
|
||||
*
|
||||
* @return 数据
|
||||
*/
|
||||
public Optional<T> oneOpt() {
|
||||
return Optional.ofNullable(one());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据实体类构建的条件获取多条数据。
|
||||
*
|
||||
* @return 数据列表
|
||||
*/
|
||||
public List<T> list() {
|
||||
return baseMapper().selectListByQuery(getQueryWrapper());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据实体类构建的条件获取分页数据。
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @return 分页数据
|
||||
*/
|
||||
public Page<T> page(Page<T> page) {
|
||||
return baseMapper().paginate(page, getQueryWrapper());
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user