mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix toBean bug
This commit is contained in:
parent
0c2fd4e9a5
commit
78b1844590
@ -7,6 +7,7 @@
|
||||
|
||||
### 新特性
|
||||
### Bug修复
|
||||
* 【setting】 修复Props.toBean方法null的问题
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -1,19 +1,5 @@
|
||||
package cn.hutool.setting.dialect;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.WatchEvent;
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
@ -39,6 +25,20 @@ import cn.hutool.log.LogFactory;
|
||||
import cn.hutool.log.StaticLog;
|
||||
import cn.hutool.setting.SettingRuntimeException;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.WatchEvent;
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Properties文件读取封装类
|
||||
*
|
||||
@ -541,7 +541,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
* @since 4.6.3
|
||||
*/
|
||||
public <T> T fillBean(T bean, String prefix) {
|
||||
prefix = StrUtil.addSuffixIfNot(prefix, StrUtil.DOT);
|
||||
prefix = StrUtil.nullToEmpty(StrUtil.addSuffixIfNot(prefix, StrUtil.DOT));
|
||||
|
||||
String key;
|
||||
for (java.util.Map.Entry<Object, Object> entry : this.entrySet()) {
|
||||
|
@ -1,17 +1,19 @@
|
||||
package cn.hutool.setting.test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.log.LogFactory;
|
||||
import cn.hutool.log.dialect.console.ConsoleLogFactory;
|
||||
import cn.hutool.setting.dialect.Props;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.log.LogFactory;
|
||||
import cn.hutool.log.dialect.console.ConsoleLogFactory;
|
||||
import cn.hutool.setting.dialect.Props;
|
||||
import lombok.Data;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Setting单元测试
|
||||
@ -67,6 +69,25 @@ public class PropsTest {
|
||||
Assert.assertEquals("owner@mail.com", cfg.getDefaultRecipients().get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toBeanWithNullPrefixTest(){
|
||||
Props configProp = new Props();
|
||||
Boolean isInit = configProp.getBool("isInit");
|
||||
|
||||
configProp.setProperty("createTime", Objects.requireNonNull(DateUtil.parse("2020-01-01")));
|
||||
configProp.setProperty("isInit", true);
|
||||
configProp.setProperty("stairPlan", 1);
|
||||
configProp.setProperty("stageNum", 2);
|
||||
configProp.setProperty("version", 3);
|
||||
SystemConfig systemConfig = configProp.toBean(SystemConfig.class);
|
||||
|
||||
Assert.assertEquals(DateUtil.parse("2020-01-01"), systemConfig.getCreateTime());
|
||||
Assert.assertEquals(true, systemConfig.getIsInit());
|
||||
Assert.assertEquals("1", systemConfig.getStairPlan());
|
||||
Assert.assertEquals(new Integer(2), systemConfig.getStageNum());
|
||||
Assert.assertEquals("3", systemConfig.getVersion());
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class ConfigProperties {
|
||||
private String host;
|
||||
@ -83,4 +104,19 @@ public class PropsTest {
|
||||
private String username;
|
||||
private String password;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class SystemConfig {
|
||||
private Boolean isInit;//是否初始化
|
||||
private Date createTime;//系统创建时间
|
||||
private String version;//系统版本
|
||||
private String ServiceOS;//服务器系统
|
||||
private String stairPlan;//周期计划 1 自然年周期,2 自然月周期,3 季度周期 4 自定义周期
|
||||
private Date startDate;//周期开始日期
|
||||
private Date nextStartDate;//下一周期开始日期
|
||||
private Integer stageNum;//阶段数目
|
||||
private Integer[] stageContent;//阶段详情
|
||||
private Date theStageTime;//当前阶段开始日期
|
||||
private Date nextStageTime;//当前阶段结束日期/下一阶段开始日期
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user