Created
September 1, 2018 02:58
-
-
Save masanobuimai/bf6addfc4cf02cc7a48893c86c3f8f5d to your computer and use it in GitHub Desktop.
スタンドアロンELのサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example; | |
import javax.el.*; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.function.Supplier; | |
public class ELTest { | |
public static void main(String[] args) { | |
ELManager elManager = new ELProcessor().getELManager(); | |
StandardELContext ctx = elManager.getELContext(); | |
ExpressionFactory factory = ELManager.getExpressionFactory(); | |
elManager.setVariable("foo", factory.createValueExpression("hoge", String.class)); | |
elManager.setVariable("bar", | |
factory.createValueExpression( | |
((Supplier<Map>) () -> { | |
Map map = new HashMap(); | |
map.put("a", "あいうえお"); | |
map.put("b", "かきくけこ"); | |
return map; | |
}).get(), Map.class)); | |
ValueExpression exp = factory.createValueExpression( | |
ctx, | |
"テキスト:${foo}\n${bar['a']} ${bar['b']}", | |
String.class); | |
System.out.println(exp.getValue(ctx)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment