- 调用函数
理解Bean就是一个Map , Map就是一个Bean. 他们之间是可以序列化互转的. 最为典型的互转就是json互转.
虽然他们本质上是一样的,但是理解和使用的难易程度上,则是一个天上,一个地下,Bean.property觉得是天经地义的。Officers[‘president‘] 就难以理解了。
package com.raycloud.api.common.core.http;import lombok.Getter;import lombok.Setter;import org.springframework.expression.Expression;import org.springframework.expression.ExpressionParser;import org.springframework.expression.spel.standard.SpelExpressionParser;import org.springframework.expression.spel.support.StandardEvaluationContext;/*** @author luobo.cs@raycloud.com* @since 2021/7/16 4:41 下午*/public class El {public static void main(String[] args) throws Exception {ExpressionParser parser = new SpelExpressionParser();StandardEvaluationContext context = new StandardEvaluationContext();context.setVariable("chen", "shun");context.setVariable("ha", 22);context.setVariable("Temp", new Temp());context.registerFunction("reverseString1", El.class.getDeclaredMethod("hello", String.class, Integer.class));context.registerFunction("reverseString2", El.class.getDeclaredMethod("hello", Temp.class));final Expression expression = parser.parseExpression("#reverseString2(#Temp)");System.out.println(expression.getValue(context, Boolean.class));}public static boolean hello(String name, Integer ha) {System.out.println(ha);return name.equals("shun");}public static boolean hello(Temp temp) {System.out.println(temp.getAge());return temp.getName().equals("shun");}@Getter@Setterpublic static class Temp {private String name = "chenshun00";private Integer age = 25;}}
output
22true
