mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
feat:属性拷贝选项添加属性过滤器
This commit is contained in:
@@ -6,6 +6,7 @@ import cn.hutool.core.bean.copier.ValueProvider;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -461,6 +462,18 @@ public class BeanUtilTest {
|
||||
Assert.assertNull(newFood.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copyBeanPropertiesFilterTest() {
|
||||
Food info = new Food();
|
||||
info.setBookID("0");
|
||||
info.setCode("");
|
||||
Food newFood = new Food();
|
||||
CopyOptions copyOptions = CopyOptions.create().setPropertiesFilter((f, v) -> !(v instanceof CharSequence) || StrUtil.isNotBlank(v.toString()));
|
||||
BeanUtil.copyProperties(info, newFood, copyOptions);
|
||||
Assert.assertEquals(info.getBookID(), newFood.getBookID());
|
||||
Assert.assertNull(newFood.getCode());
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Food {
|
||||
@Alias("bookId")
|
||||
|
Reference in New Issue
Block a user