3.2.9.3.3. 默认值

可以为配置接口定义的属性指定默认值。如果未在存储位置(数据库或 *app.properties 文件)中设置该属性,则将返回这里定义的默认值而不是 null

可以使用 @Default 注解将默认值指定为字符串,或使用 com.haulmont.cuba.core.config.defaults 包中的其它注解将默认值指定为其它特定类型:

  1. @Property("cuba.email.adminAddress")
  2. @Default("address@company.com")
  3. String getAdminAddress();
  4. @Property("cuba.email.delayCallCount")
  5. @Default("2")
  6. int getDelayCallCount();
  7. @Property("cuba.email.defaultSendingAttemptsCount")
  8. @DefaultInt(10)
  9. int getDefaultSendingAttemptsCount();
  10. @Property("cuba.test.dateProp")
  11. @Default("2013-12-12 00:00:00.000")
  12. @Factory(factory = DateFactory.class)
  13. Date getDateProp();
  14. @Property("cuba.test.integerList")
  15. @Default("1 2 3")
  16. @Factory(factory = IntegerListTypeFactory.class)
  17. List<Integer> getIntegerList();
  18. @Property("cuba.test.stringList")
  19. @Default("aaa|bbb|ccc")
  20. @Factory(factory = StringListTypeFactory.class)
  21. List<String> getStringList();

实体的默认值是 {entity_name}-{id}-{optional_view_name} 格式的字符串,例如:

  1. @Default("sec$User-98e5e66c-3ac9-11e2-94c1-3860770d7eaf-browse")
  2. User getAdminUser();
  3. @Default("sec$Role-a294aef0-3ac9-11e2-9433-3860770d7eaf")
  4. Role getAdminRole();