当前位置: 首页>>代码示例>>Java>>正文


Java StandardEvaluationContext.setTypeConverter方法代码示例

本文整理汇总了Java中org.springframework.expression.spel.support.StandardEvaluationContext.setTypeConverter方法的典型用法代码示例。如果您正苦于以下问题:Java StandardEvaluationContext.setTypeConverter方法的具体用法?Java StandardEvaluationContext.setTypeConverter怎么用?Java StandardEvaluationContext.setTypeConverter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.expression.spel.support.StandardEvaluationContext的用法示例。


在下文中一共展示了StandardEvaluationContext.setTypeConverter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: registerConversionServiceInSpelExpressions

import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
private void registerConversionServiceInSpelExpressions(Expression parsedExpression) {
  if (conversionService == null) {
    return;
  }
  StandardTypeConverter converter = new StandardTypeConverter(conversionService);
  StandardEvaluationContext context = new StandardEvaluationContext();
  context.setTypeConverter(converter);
  setContextIfSpelExpression(parsedExpression, context);

  if (parsedExpression instanceof CompositeStringExpression) {
    CompositeStringExpression composite = (CompositeStringExpression) parsedExpression;
    for (Expression childExpresion : composite.getExpressions()) {
      setContextIfSpelExpression(childExpresion, context);
    }
  }
}
 
开发者ID:DISID,项目名称:springlets,代码行数:17,代码来源:EntityExpressionSupport.java

示例2: createEvaluationContext

import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
private EvaluationContext createEvaluationContext(PageContext pageContext) {
	StandardEvaluationContext context = new StandardEvaluationContext();
	context.addPropertyAccessor(new JspPropertyAccessor(pageContext));
	context.addPropertyAccessor(new MapAccessor());
	context.addPropertyAccessor(new EnvironmentAccessor());
	context.setBeanResolver(new BeanFactoryResolver(getRequestContext().getWebApplicationContext()));
	ConversionService conversionService = getConversionService(pageContext);
	if (conversionService != null) {
		context.setTypeConverter(new StandardTypeConverter(conversionService));
	}
	return context;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:EvalTag.java

示例3: test_binaryPlusWithTimeConverted

import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
@Test
public void test_binaryPlusWithTimeConverted() {

	final SimpleDateFormat format = new SimpleDateFormat("hh :--: mm :--: ss", Locale.ENGLISH);

	GenericConversionService conversionService = new GenericConversionService();
	conversionService.addConverter(new Converter<Time, String>() {
		@Override
		public String convert(Time source) {
			return format.format(source);
		}
	});

	StandardEvaluationContext evaluationContextConverter = new StandardEvaluationContext();
	evaluationContextConverter.setTypeConverter(new StandardTypeConverter(conversionService));

	ExpressionState expressionState = new ExpressionState(evaluationContextConverter);

	Time time = new Time(new Date().getTime());

	VariableReference var = new VariableReference("timeVar", -1);
	var.setValue(expressionState, time);

	StringLiteral n2 = new StringLiteral("\" is now\"", -1, "\" is now\"");
	OpPlus o = new OpPlus(-1, var, n2);
	TypedValue value = o.getValueInternal(expressionState);

	assertEquals(String.class, value.getTypeDescriptor().getObjectType());
	assertEquals(String.class, value.getTypeDescriptor().getType());
	assertEquals(format.format(time) + " is now", value.getValue());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:32,代码来源:OpPlusTests.java

示例4: testSetParameterizedList

import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
@Test
public void testSetParameterizedList() throws Exception {
	StandardEvaluationContext context = TestScenarioCreator.getTestEvaluationContext();
	Expression e = parser.parseExpression("listOfInteger.size()");
	assertEquals(0,e.getValue(context,Integer.class).intValue());
	context.setTypeConverter(new TypeConvertorUsingConversionService());
	// Assign a List<String> to the List<Integer> field - the component elements should be converted
	parser.parseExpression("listOfInteger").setValue(context,listOfString);
	assertEquals(3,e.getValue(context,Integer.class).intValue()); // size now 3
	Class<?> clazz = parser.parseExpression("listOfInteger[1].getClass()").getValue(context, Class.class); // element type correctly Integer
	assertEquals(Integer.class,clazz);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:ExpressionWithConversionTests.java


注:本文中的org.springframework.expression.spel.support.StandardEvaluationContext.setTypeConverter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。