对于最新稳定版本,请使用Spring Framework 7.0.1spring-doc.cadn.net.cn

属性、数组、列表、映射和索引器

使用房产推荐信导航非常简单。为此,使用句号表示嵌套 房产价值。以下实例发明家特斯拉, 填充了示例部分所用类别中列出的数据。要“往下”导航对象图,获取特斯拉的出生年份, 普平的出生城市,我们使用以下表达:spring-doc.cadn.net.cn

// evaluates to 1856
int year = (Integer) parser.parseExpression("birthdate.year + 1900").getValue(context);

String city = (String) parser.parseExpression("placeOfBirth.city").getValue(context);
// evaluates to 1856
val year = parser.parseExpression("birthdate.year + 1900").getValue(context) as Int

val city = parser.parseExpression("placeOfBirth.city").getValue(context) as String

房产名称的首字母允许大小写不区分。因此, 上述示例中的表达式可以写成出生日期。年份 + 1900出生地。城市分别。此外,房产还可选择性地通过以下方式访问 方法调用——例如,getPlaceOfBirth().getCity()而不是出生地.city.spring-doc.cadn.net.cn

数组和列表的内容通过方括号表示法获得,表示为 以下示例展示了:spring-doc.cadn.net.cn

ExpressionParser parser = new SpelExpressionParser();
EvaluationContext context = SimpleEvaluationContext.forReadOnlyDataBinding().build();

// Inventions Array

// evaluates to "Induction motor"
String invention = parser.parseExpression("inventions[3]").getValue(
		context, tesla, String.class);

// Members List

// evaluates to "Nikola Tesla"
String name = parser.parseExpression("members[0].name").getValue(
		context, ieee, String.class);

// List and Array navigation
// evaluates to "Wireless communication"
String invention = parser.parseExpression("members[0].inventions[6]").getValue(
		context, ieee, String.class);
val parser = SpelExpressionParser()
val context = SimpleEvaluationContext.forReadOnlyDataBinding().build()

// Inventions Array

// evaluates to "Induction motor"
val invention = parser.parseExpression("inventions[3]").getValue(
		context, tesla, String::class.java)

// Members List

// evaluates to "Nikola Tesla"
val name = parser.parseExpression("members[0].name").getValue(
		context, ieee, String::class.java)

// List and Array navigation
// evaluates to "Wireless communication"
val invention = parser.parseExpression("members[0].inventions[6]").getValue(
		context, ieee, String::class.java)

映射的内容通过在 括弧。在以下例子中,因为人员映射是字符串,我们可以指定 字符串:spring-doc.cadn.net.cn

// Officer's Dictionary

Inventor pupin = parser.parseExpression("officers['president']").getValue(
		societyContext, Inventor.class);

// evaluates to "Idvor"
String city = parser.parseExpression("officers['president'].placeOfBirth.city").getValue(
		societyContext, String.class);

// setting values
parser.parseExpression("officers['advisors'][0].placeOfBirth.country").setValue(
		societyContext, "Croatia");
// Officer's Dictionary

val pupin = parser.parseExpression("officers['president']").getValue(
		societyContext, Inventor::class.java)

// evaluates to "Idvor"
val city = parser.parseExpression("officers['president'].placeOfBirth.city").getValue(
		societyContext, String::class.java)

// setting values
parser.parseExpression("officers['advisors'][0].placeOfBirth.country").setValue(
		societyContext, "Croatia")