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
1eb8acfcba
commit
10ffd8750b
@ -142,15 +142,15 @@ public class BeanPath implements Serializable {
|
||||
* @param patternParts 表达式块列表
|
||||
* @param value 值
|
||||
*/
|
||||
private Object set(final Object bean, final List<String> patternParts, final boolean nextNumberPart, final Object value) {
|
||||
private void set(final Object bean, final List<String> patternParts, final boolean nextNumberPart, final Object value) {
|
||||
Object subBean = this.get(patternParts, bean, true);
|
||||
if (null == subBean) {
|
||||
final List<String> parentParts = getParentParts(patternParts);
|
||||
// 避免get方法的重复调用
|
||||
subBean = this.set(bean, parentParts, lastIsNumber(parentParts), nextNumberPart ? new ArrayList<>() : new HashMap<>());
|
||||
this.set(bean, parentParts, lastIsNumber(parentParts), nextNumberPart ? new ArrayList<>() : new HashMap<>());
|
||||
//set中有可能做过转换,因此此处重新获取bean
|
||||
subBean = this.get(patternParts, bean, true);
|
||||
}
|
||||
BeanUtil.setFieldValue(subBean, patternParts.get(patternParts.size() - 1), value);
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,6 +2,7 @@ package cn.hutool.core.bean;
|
||||
|
||||
import cn.hutool.core.lang.test.bean.ExamInfoDict;
|
||||
import cn.hutool.core.lang.test.bean.UserInfoDict;
|
||||
import cn.hutool.core.map.Dict;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -144,4 +145,11 @@ public class BeanPathTest {
|
||||
beanPath.set(map, "张三");
|
||||
Assert.assertEquals("{list=[[null, {name=张三}]]}", map.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void putByPathTest() {
|
||||
final Dict dict = new Dict();
|
||||
BeanPath.of("aa.bb").set(dict, "BB");
|
||||
Assert.assertEquals("{aa={bb=BB}}", dict.toString());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user