feilong
feilong copied to clipboard
参考 这种设置值
/**
- 设置默认值
*/ public class ValueUtils{
/**
* 如果judgeValue的值为null且value不为null则调用set.accept方法
*
* @param judgeValue
* 待判断的值
* @param set
* 设置器
* @param value
* 给与设置器的值
*/
public static <T> void setValueIfNull(Supplier<T> judgeValue,Consumer<T> set,T value){
if (judgeValue.get() == null && value != null){
set.accept(value);
}
}
public static <T> void setValueIfNotNull(Supplier<T> newValue,Consumer<T> consumer){
if (newValue.get() != null){
consumer.accept(newValue.get());
}
}
}
// 默认主站专辑 ValueUtils.setValueIfNull(albumQueryDTO::getAlbumScope, albumQueryDTO::setAlbumScope, "111111");