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