学习内容源于 官方文档 https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#expressions

 

学习摘要:

SpEL: Spring Express Language, a java expression language.

Other known expression Language: OGNL, MVEL, JBoss EL ...

 

SpEL 支持的功能

  • Literal expressions:  "'Hello world'"
  • Boolean and relational operators:    "false", "true", " 1 > 5" 
  • Regular expressions
  • Class expressions
  • Accessing properties, arrays, lists, and maps: "a.b" , "new arr[4]","arr[0]", "{1,2,3}", "m['key']" "{k1:v1,k2:v2}"
  • Method invocation: "'abc'.substring(1,3)"
  • Relational operators : "2 == 2" , "'xyz' instanceof T<Integer>"  "'5.00' matches '^-?\\d+(\\.\\d{2})?$'")
  • Assignment: " v1='hello world' "
  • Calling constructors : "new org.spring.samples.spel.inventor.Inventor('Albert Einstein', 'German')​"
  • Bean references: "@something"
  • Array construction: 
  • Inline lists : "{1,2,3}"
  • Inline maps: "{k1:v1,k2:v2}"
  • Ternary operator : "true?trueExp:falseExp"
  • Variables : #varibleName, #this, #root
  • User-defined functions
  • Collection projection
  • Collection selection
  • Templated expressions

 

  • "name?:'Unknow'"  
  • "object1?.property1"
  • "members.?[country=='China']"
  • "map.?[value < 10]"
  • "collection.^[selectionExpression]"
  • "collection.$[selectionExpression]"
  • "collection.![projectionExpression]"
  • #{}
  • "This value is #{1+2}"

 

遇到的类(org.springframework.expression):

  • SpelExpressionPareser

 

发表评论