本文整理匯總了Java中org.springframework.expression.EvaluationContext.setVariable方法的典型用法代碼示例。如果您正苦於以下問題:Java EvaluationContext.setVariable方法的具體用法?Java EvaluationContext.setVariable怎麽用?Java EvaluationContext.setVariable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.expression.EvaluationContext
的用法示例。
在下文中一共展示了EvaluationContext.setVariable方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getUserInfos
import org.springframework.expression.EvaluationContext; //導入方法依賴的package包/類
@Override
public Map<String, String> getUserInfos(User user, HttpServletRequest request, final Map<String, String> userInfosInComputing) {
Map<String, String> userInfos = new HashMap<String, String>();
for(String name: sgcParam2spelExp.keySet()) {
String expression = sgcParam2spelExp.get(name);
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression(expression);
EvaluationContext context = new StandardEvaluationContext();
context.setVariable("user", user);
context.setVariable("request", request);
context.setVariable("userInfosInComputing", userInfosInComputing);
context.setVariable("dateUtils", dateUtils);
String value = (String) exp.getValue(context);
userInfos.put(name, value);
}
return userInfos;
}
示例2: validate_spring_expression
import org.springframework.expression.EvaluationContext; //導入方法依賴的package包/類
@Ignore
@Test
public void validate_spring_expression ()
throws Exception {
// String url = "http://csaptools.yourcompany.com/admin/api/clusters";
String url = "http://testhost.yourcompany.com:8011/CsAgent/api/collection/application/CsAgent_8011/30/10";
ObjectNode restResponse = analyticsTemplate.getForObject( url, ObjectNode.class );
logger.info( "Url: {} response: {}", url, jacksonMapper.writerWithDefaultPrettyPrinter()
.writeValueAsString( restResponse ) );
ArrayList<Integer> publishvals = jacksonMapper.readValue(
restResponse.at( "/data/publishEvents" )
.traverse(),
new TypeReference<ArrayList<Integer>>() {
} );
int total = publishvals.stream().mapToInt( Integer::intValue ).sum();
logger.info( "Total: {} publishvals: {}", total, publishvals );
EvaluationContext context = new StandardEvaluationContext();
context.setVariable( "total", total );
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression( "#total.toString()" );
logger.info( "SPEL evalutation: {}", (String) exp.getValue( context ) );
exp = parser.parseExpression( "#total > 99" );
logger.info( "#total > 99 SPEL evalutation: {}", (Boolean) exp.getValue( context ) );
exp = parser.parseExpression( "#total > 3" );
logger.info( "#total > 3 SPEL evalutation: {}", (Boolean) exp.getValue( context ) );
}