Skip to content

Commit baac369

Browse files
authored
Merge pull request #1582 from swtseaman/master
- add: Value注解增加默认值支持
2 parents 7e96c2d + d9483cc commit baac369

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/org/nutz/ioc/loader/annotation/AnnotationIocLoader.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,13 @@ public void addClass(Class<?> classZ) {
167167
} else {
168168
configName = value.name();
169169
}
170-
IocValue iocValue = Iocs.convert(String.format("java:$conf.get('%s')", configName), true);
170+
String defaultValue = value.defaultValue();
171+
IocValue iocValue;
172+
if(Strings.isBlank(defaultValue)) {
173+
iocValue = Iocs.convert(String.format("java:$conf.get('%s')", configName), true);
174+
} else {
175+
iocValue = Iocs.convert(String.format("java:$conf.get('%s', '%s')", configName, defaultValue), true);
176+
}
171177
IocField iocField = new IocField();
172178
iocField.setName(valueField.getName());
173179
iocField.setValue(iocValue);

src/org/nutz/ioc/loader/annotation/Value.java

+6
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,10 @@
1717
* @return
1818
*/
1919
String name() default "";
20+
21+
/**
22+
* 配置项默认值
23+
* @return
24+
*/
25+
String defaultValue() default "";
2026
}

0 commit comments

Comments
 (0)