本文整理汇总了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 ) );
}