optimize IService.java

This commit is contained in:
开源海哥 2023-06-01 18:25:23 +08:00
parent f21e918861
commit 571ea137fd

View File

@ -60,6 +60,7 @@ public interface IService<T> {
return SqlUtil.toBool(getMapper().insertSelective(entity));
}
/**
* 保存或者更新实体类对象数据
*
@ -149,6 +150,29 @@ public interface IService<T> {
return SqlUtil.toBool(getMapper().deleteByMap(query));
}
/**
* 更加主键更新 entity默认忽略 null
*
* @param entity 实体类对象
* @return {@code true} 更新成功{@code false} 更新失败
*/
default boolean updateById(T entity) {
return updateById(entity, true);
}
/**
* 更加主键更新 entity
*
* @param entity entity
* @param ignoreNulls 是否忽略 null
* @return {@code true} 更新成功{@code false} 更新失败
*/
default boolean updateById(T entity, boolean ignoreNulls) {
return SqlUtil.toBool(getMapper().update(entity, ignoreNulls));
}
/**
* 根据查询条件更新数据
*
@ -160,6 +184,18 @@ public interface IService<T> {
return SqlUtil.toBool(getMapper().updateByQuery(entity, query));
}
/**
* 根据 {@link Map} 构建查询条件更新数据
*
* @param entity 实体类对象
* @param query 查询条件
* @return {@code true} 更新成功{@code false} 更新失败
*/
default boolean update(T entity, Map<String, Object> query) {
return SqlUtil.toBool(getMapper().updateByMap(entity, query));
}
/**
* 根据查询条件更新数据
*
@ -199,26 +235,6 @@ public interface IService<T> {
});
}
/**
* 根据数据主键更新数据
*
* @param entity 实体类对象
* @return {@code true} 更新成功{@code false} 更新失败
*/
default boolean updateById(T entity) {
return SqlUtil.toBool(getMapper().update(entity));
}
/**
* 根据 {@link Map} 构建查询条件更新数据
*
* @param entity 实体类对象
* @param query 查询条件
* @return {@code true} 更新成功{@code false} 更新失败
*/
default boolean updateByMap(T entity, Map<String, Object> query) {
return SqlUtil.toBool(getMapper().updateByMap(entity, query));
}
// ===== 查询操作 =====