mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix code
This commit is contained in:
parent
0e9a1a700f
commit
dc46dfd9e5
@ -12,7 +12,10 @@
|
|||||||
|
|
||||||
package org.dromara.hutool.core.bean.copier;
|
package org.dromara.hutool.core.bean.copier;
|
||||||
|
|
||||||
|
import org.dromara.hutool.core.bean.BeanDesc;
|
||||||
|
import org.dromara.hutool.core.bean.BeanUtil;
|
||||||
import org.dromara.hutool.core.lang.copier.Copier;
|
import org.dromara.hutool.core.lang.copier.Copier;
|
||||||
|
import org.dromara.hutool.core.reflect.ConstructorUtil;
|
||||||
import org.dromara.hutool.core.util.ObjUtil;
|
import org.dromara.hutool.core.util.ObjUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,4 +47,21 @@ public abstract class AbsCopier<S, T> implements Copier<T> {
|
|||||||
this.target = target;
|
this.target = target;
|
||||||
this.copyOptions = ObjUtil.defaultIfNull(copyOptions, CopyOptions::of);
|
this.copyOptions = ObjUtil.defaultIfNull(copyOptions, CopyOptions::of);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取Bean描述信息<br>
|
||||||
|
* 如果用户自定义了{@link BeanDesc}实现,则使用,否则使用默认的规则
|
||||||
|
*
|
||||||
|
* @param actualEditable 需要解析的类
|
||||||
|
* @return {@link BeanDesc}
|
||||||
|
*/
|
||||||
|
protected BeanDesc getBeanDesc(final Class<?> actualEditable) {
|
||||||
|
if (null != this.copyOptions) {
|
||||||
|
final Class<BeanDesc> beanDescClass = copyOptions.beanDescClass;
|
||||||
|
if (null != beanDescClass) {
|
||||||
|
return ConstructorUtil.newInstance(beanDescClass, actualEditable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return BeanUtil.getBeanDesc(actualEditable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
package org.dromara.hutool.core.bean.copier;
|
package org.dromara.hutool.core.bean.copier;
|
||||||
|
|
||||||
import org.dromara.hutool.core.bean.BeanUtil;
|
|
||||||
import org.dromara.hutool.core.bean.PropDesc;
|
import org.dromara.hutool.core.bean.PropDesc;
|
||||||
import org.dromara.hutool.core.lang.Assert;
|
import org.dromara.hutool.core.lang.Assert;
|
||||||
import org.dromara.hutool.core.lang.mutable.MutableEntry;
|
import org.dromara.hutool.core.lang.mutable.MutableEntry;
|
||||||
@ -58,9 +57,9 @@ public class BeanToBeanCopier<S, T> extends AbsCopier<S, T> {
|
|||||||
"Target class [{}] not assignable to Editable class [{}]", actualEditable.getName(), copyOptions.editable.getName());
|
"Target class [{}] not assignable to Editable class [{}]", actualEditable.getName(), copyOptions.editable.getName());
|
||||||
actualEditable = copyOptions.editable;
|
actualEditable = copyOptions.editable;
|
||||||
}
|
}
|
||||||
final Map<String, PropDesc> targetPropDescMap = BeanUtil.getBeanDesc(actualEditable).getPropMap(copyOptions.ignoreCase);
|
final Map<String, PropDesc> targetPropDescMap = getBeanDesc(actualEditable).getPropMap(copyOptions.ignoreCase);
|
||||||
|
|
||||||
final Map<String, PropDesc> sourcePropDescMap = BeanUtil.getBeanDesc(source.getClass()).getPropMap(copyOptions.ignoreCase);
|
final Map<String, PropDesc> sourcePropDescMap = getBeanDesc(source.getClass()).getPropMap(copyOptions.ignoreCase);
|
||||||
sourcePropDescMap.forEach((sFieldName, sDesc) -> {
|
sourcePropDescMap.forEach((sFieldName, sDesc) -> {
|
||||||
if (null == sFieldName || !sDesc.isReadable(copyOptions.transientSupport)) {
|
if (null == sFieldName || !sDesc.isReadable(copyOptions.transientSupport)) {
|
||||||
// 字段空或不可读,跳过
|
// 字段空或不可读,跳过
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
package org.dromara.hutool.core.bean.copier;
|
package org.dromara.hutool.core.bean.copier;
|
||||||
|
|
||||||
import org.dromara.hutool.core.bean.BeanUtil;
|
|
||||||
import org.dromara.hutool.core.bean.PropDesc;
|
import org.dromara.hutool.core.bean.PropDesc;
|
||||||
import org.dromara.hutool.core.lang.Assert;
|
import org.dromara.hutool.core.lang.Assert;
|
||||||
import org.dromara.hutool.core.lang.mutable.MutableEntry;
|
import org.dromara.hutool.core.lang.mutable.MutableEntry;
|
||||||
@ -59,7 +58,7 @@ public class BeanToMapCopier extends AbsCopier<Object, Map> {
|
|||||||
actualEditable = copyOptions.editable;
|
actualEditable = copyOptions.editable;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Map<String, PropDesc> sourcePropDescMap = BeanUtil.getBeanDesc(actualEditable).getPropMap(copyOptions.ignoreCase);
|
final Map<String, PropDesc> sourcePropDescMap = getBeanDesc(actualEditable).getPropMap(copyOptions.ignoreCase);
|
||||||
sourcePropDescMap.forEach((sFieldName, sDesc) -> {
|
sourcePropDescMap.forEach((sFieldName, sDesc) -> {
|
||||||
if (null == sFieldName || !sDesc.isReadable(copyOptions.transientSupport)) {
|
if (null == sFieldName || !sDesc.isReadable(copyOptions.transientSupport)) {
|
||||||
// 字段空或不可读,跳过
|
// 字段空或不可读,跳过
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
package org.dromara.hutool.core.bean.copier;
|
package org.dromara.hutool.core.bean.copier;
|
||||||
|
|
||||||
|
import org.dromara.hutool.core.bean.BeanDesc;
|
||||||
import org.dromara.hutool.core.bean.PropDesc;
|
import org.dromara.hutool.core.bean.PropDesc;
|
||||||
import org.dromara.hutool.core.convert.Convert;
|
import org.dromara.hutool.core.convert.Convert;
|
||||||
import org.dromara.hutool.core.convert.Converter;
|
import org.dromara.hutool.core.convert.Converter;
|
||||||
@ -90,6 +91,12 @@ public class CopyOptions implements Serializable {
|
|||||||
*/
|
*/
|
||||||
protected boolean autoTransCamelCase = true;
|
protected boolean autoTransCamelCase = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义的Bean解析类<br>
|
||||||
|
* 默认规则下普通Bean使用严格的Bean解析,需要同时解析Bean中的字段和方法,然后匹配,自定义后可以只解析getter和setter方法
|
||||||
|
*/
|
||||||
|
protected Class<BeanDesc> beanDescClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义类型转换器,默认使用全局万能转换器转换
|
* 自定义类型转换器,默认使用全局万能转换器转换
|
||||||
*/
|
*/
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
package org.dromara.hutool.core.bean.copier;
|
package org.dromara.hutool.core.bean.copier;
|
||||||
|
|
||||||
import org.dromara.hutool.core.bean.BeanUtil;
|
|
||||||
import org.dromara.hutool.core.bean.PropDesc;
|
import org.dromara.hutool.core.bean.PropDesc;
|
||||||
import org.dromara.hutool.core.lang.Assert;
|
import org.dromara.hutool.core.lang.Assert;
|
||||||
import org.dromara.hutool.core.lang.mutable.MutableEntry;
|
import org.dromara.hutool.core.lang.mutable.MutableEntry;
|
||||||
@ -67,7 +66,7 @@ public class MapToBeanCopier<T> extends AbsCopier<Map<?, ?>, T> {
|
|||||||
"Target class [{}] not assignable to Editable class [{}]", actualEditable.getName(), copyOptions.editable.getName());
|
"Target class [{}] not assignable to Editable class [{}]", actualEditable.getName(), copyOptions.editable.getName());
|
||||||
actualEditable = copyOptions.editable;
|
actualEditable = copyOptions.editable;
|
||||||
}
|
}
|
||||||
final Map<String, PropDesc> targetPropDescMap = BeanUtil.getBeanDesc(actualEditable).getPropMap(copyOptions.ignoreCase);
|
final Map<String, PropDesc> targetPropDescMap = getBeanDesc(actualEditable).getPropMap(copyOptions.ignoreCase);
|
||||||
|
|
||||||
this.source.forEach((sKey, sValue) -> {
|
this.source.forEach((sKey, sValue) -> {
|
||||||
if (null == sKey) {
|
if (null == sKey) {
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
package org.dromara.hutool.core.bean.copier;
|
package org.dromara.hutool.core.bean.copier;
|
||||||
|
|
||||||
import org.dromara.hutool.core.bean.BeanUtil;
|
|
||||||
import org.dromara.hutool.core.bean.PropDesc;
|
import org.dromara.hutool.core.bean.PropDesc;
|
||||||
import org.dromara.hutool.core.lang.Assert;
|
import org.dromara.hutool.core.lang.Assert;
|
||||||
import org.dromara.hutool.core.lang.mutable.MutableEntry;
|
import org.dromara.hutool.core.lang.mutable.MutableEntry;
|
||||||
@ -57,7 +56,7 @@ public class ValueProviderToBeanCopier<T> extends AbsCopier<ValueProvider<String
|
|||||||
"Target class [{}] not assignable to Editable class [{}]", actualEditable.getName(), copyOptions.editable.getName());
|
"Target class [{}] not assignable to Editable class [{}]", actualEditable.getName(), copyOptions.editable.getName());
|
||||||
actualEditable = copyOptions.editable;
|
actualEditable = copyOptions.editable;
|
||||||
}
|
}
|
||||||
final Map<String, PropDesc> targetPropDescMap = BeanUtil.getBeanDesc(actualEditable).getPropMap(copyOptions.ignoreCase);
|
final Map<String, PropDesc> targetPropDescMap = getBeanDesc(actualEditable).getPropMap(copyOptions.ignoreCase);
|
||||||
|
|
||||||
targetPropDescMap.forEach((tFieldName, tDesc) -> {
|
targetPropDescMap.forEach((tFieldName, tDesc) -> {
|
||||||
if (null == tFieldName) {
|
if (null == tFieldName) {
|
||||||
|
@ -36,8 +36,21 @@ public class BeanValueProvider implements ValueProvider<String> {
|
|||||||
* @param bean Bean
|
* @param bean Bean
|
||||||
*/
|
*/
|
||||||
public BeanValueProvider(final Object bean) {
|
public BeanValueProvider(final Object bean) {
|
||||||
|
this(bean, BeanUtil.getBeanDesc(bean.getClass()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造
|
||||||
|
*
|
||||||
|
* @param bean Bean
|
||||||
|
* @param beanDesc 自定义的{@link BeanDesc},默认为{@link BeanUtil#getBeanDesc(Class)}
|
||||||
|
*/
|
||||||
|
public BeanValueProvider(final Object bean, BeanDesc beanDesc) {
|
||||||
this.bean = bean;
|
this.bean = bean;
|
||||||
this.beanDesc = BeanUtil.getBeanDesc(bean.getClass());
|
if(null == beanDesc){
|
||||||
|
beanDesc = BeanUtil.getBeanDesc(bean.getClass());
|
||||||
|
}
|
||||||
|
this.beanDesc = beanDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user