java中两个实体类转换,如果为空,忽略这个属性

    static void copyNonNullPropertiesStatic(Object source, Object target) {
        final BeanWrapper wrappedSource = new BeanWrapperImpl(source);

        String[] nullPropertyNames = Stream.of(wrappedSource.getPropertyDescriptors())
                .map(FeatureDescriptor::getName)
                .filter(propertyName -> wrappedSource.getPropertyValue(propertyName) == null)
                .toArray(String[]::new);

        BeanUtils.copyProperties(source, target, nullPropertyNames);
    }

你可能感兴趣的:(java中两个实体类转换,如果为空,忽略这个属性)