Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 51cac459b3 |
+60
-60
@@ -1,60 +1,60 @@
|
|||||||
package org.dromara.common.core.utils;
|
package org.dromara.common.core.utils;
|
||||||
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对象工具类
|
* 对象工具类
|
||||||
*
|
*
|
||||||
* @author 秋辞未寒
|
* @author 秋辞未寒
|
||||||
*/
|
*/
|
||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class ObjectUtils extends ObjectUtil {
|
public class ObjectUtils extends ObjectUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 如果对象不为空,则获取对象中的某个字段 ObjectUtils.notNullGetter(user, User::getName);
|
* 如果对象不为空,则获取对象中的某个字段 ObjectUtils.notNullGetter(user, User::getName);
|
||||||
*
|
*
|
||||||
* @param obj 对象
|
* @param obj 对象
|
||||||
* @param func 获取方法
|
* @param func 获取方法
|
||||||
* @return 对象字段
|
* @return 对象字段
|
||||||
*/
|
*/
|
||||||
public static <T, E> E notNullGetter(T obj, Function<T, E> func) {
|
public static <T, E> E notNullGetter(T obj, Function<T, E> func) {
|
||||||
if (isNotNull(obj) && isNotNull(func)) {
|
if (isNotNull(obj) && isNotNull(func)) {
|
||||||
return func.apply(obj);
|
return func.apply(obj);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 如果对象不为空,则获取对象中的某个字段,否则返回默认值
|
* 如果对象不为空,则获取对象中的某个字段,否则返回默认值
|
||||||
*
|
*
|
||||||
* @param obj 对象
|
* @param obj 对象
|
||||||
* @param func 获取方法
|
* @param func 获取方法
|
||||||
* @param defaultValue 默认值
|
* @param defaultValue 默认值
|
||||||
* @return 对象字段
|
* @return 对象字段
|
||||||
*/
|
*/
|
||||||
public static <T, E> E notNullGetter(T obj, Function<T, E> func, E defaultValue) {
|
public static <T, E> E notNullGetter(T obj, Function<T, E> func, E defaultValue) {
|
||||||
if (isNotNull(obj) && isNotNull(func)) {
|
if (isNotNull(obj) && isNotNull(func)) {
|
||||||
return func.apply(obj);
|
return func.apply(obj);
|
||||||
}
|
}
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 如果值不为空,则返回值,否则返回默认值
|
* 如果值不为空,则返回值,否则返回默认值
|
||||||
*
|
*
|
||||||
* @param obj 对象
|
* @param obj 对象
|
||||||
* @param defaultValue 默认值
|
* @param defaultValue 默认值
|
||||||
* @return 对象字段
|
* @return 对象字段
|
||||||
*/
|
*/
|
||||||
public static <T> T notNull(T obj, T defaultValue) {
|
public static <T> T notNull(T obj, T defaultValue) {
|
||||||
if (isNotNull(obj)) {
|
if (isNotNull(obj)) {
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -425,7 +425,7 @@ import { useTreeTableExpand } from '@/hooks/tree/useTreeTableExpand';
|
|||||||
import { useDict } from '@/utils/dict';
|
import { useDict } from '@/utils/dict';
|
||||||
</#if>
|
</#if>
|
||||||
import modal from '@/plugins/modal';
|
import modal from '@/plugins/modal';
|
||||||
import { handleTree<#if needParseTime>, parseTime</#if> } from '@/utils/ruoyi';
|
import { handleTree } from '@/utils/ruoyi';
|
||||||
<#if enableExport>
|
<#if enableExport>
|
||||||
import { download as requestDownload } from '@/utils/request';
|
import { download as requestDownload } from '@/utils/request';
|
||||||
</#if>
|
</#if>
|
||||||
|
|||||||
Reference in New Issue
Block a user