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


Java DataBinder.setConversionService方法代码示例

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


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

示例1: testAmountAndUnit

import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
@Test
public void testAmountAndUnit() {
	MoneyHolder bean = new MoneyHolder();
	DataBinder binder = new DataBinder(bean);
	binder.setConversionService(conversionService);

	MutablePropertyValues propertyValues = new MutablePropertyValues();
	propertyValues.add("amount", "USD 10.50");
	propertyValues.add("unit", "USD");
	binder.bind(propertyValues);
	assertEquals(0, binder.getBindingResult().getErrorCount());
	assertEquals("USD10.50", binder.getBindingResult().getFieldValue("amount"));
	assertEquals("USD", binder.getBindingResult().getFieldValue("unit"));
	assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d);
	assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode());

	LocaleContextHolder.setLocale(Locale.CANADA);
	binder.bind(propertyValues);
	LocaleContextHolder.setLocale(Locale.US);
	assertEquals(0, binder.getBindingResult().getErrorCount());
	assertEquals("USD10.50", binder.getBindingResult().getFieldValue("amount"));
	assertEquals("USD", binder.getBindingResult().getFieldValue("unit"));
	assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d);
	assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:MoneyFormattingTests.java

示例2: testAmountWithNumberFormat1

import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
@Test
public void testAmountWithNumberFormat1() {
	FormattedMoneyHolder1 bean = new FormattedMoneyHolder1();
	DataBinder binder = new DataBinder(bean);
	binder.setConversionService(conversionService);

	MutablePropertyValues propertyValues = new MutablePropertyValues();
	propertyValues.add("amount", "$10.50");
	binder.bind(propertyValues);
	assertEquals(0, binder.getBindingResult().getErrorCount());
	assertEquals("$10.50", binder.getBindingResult().getFieldValue("amount"));
	assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d);
	assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode());

	LocaleContextHolder.setLocale(Locale.CANADA);
	binder.bind(propertyValues);
	LocaleContextHolder.setLocale(Locale.US);
	assertEquals(0, binder.getBindingResult().getErrorCount());
	assertEquals("$10.50", binder.getBindingResult().getFieldValue("amount"));
	assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d);
	assertEquals("CAD", bean.getAmount().getCurrency().getCurrencyCode());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:MoneyFormattingTests.java

示例3: testAmountWithNumberFormat3

import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
@Test
public void testAmountWithNumberFormat3() {
	FormattedMoneyHolder3 bean = new FormattedMoneyHolder3();
	DataBinder binder = new DataBinder(bean);
	binder.setConversionService(conversionService);

	MutablePropertyValues propertyValues = new MutablePropertyValues();
	propertyValues.add("amount", "10%");
	binder.bind(propertyValues);
	assertEquals(0, binder.getBindingResult().getErrorCount());
	assertEquals("10%", binder.getBindingResult().getFieldValue("amount"));
	assertTrue(bean.getAmount().getNumber().doubleValue() == 0.1d);
	assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:15,代码来源:MoneyFormattingTests.java

示例4: testAmountWithNumberFormat5

import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
@Test
public void testAmountWithNumberFormat5() {
	FormattedMoneyHolder5 bean = new FormattedMoneyHolder5();
	DataBinder binder = new DataBinder(bean);
	binder.setConversionService(conversionService);

	MutablePropertyValues propertyValues = new MutablePropertyValues();
	propertyValues.add("amount", "USD 10.50");
	binder.bind(propertyValues);
	assertEquals(0, binder.getBindingResult().getErrorCount());
	assertEquals("USD 010.500", binder.getBindingResult().getFieldValue("amount"));
	assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d);
	assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode());

	LocaleContextHolder.setLocale(Locale.CANADA);
	binder.bind(propertyValues);
	LocaleContextHolder.setLocale(Locale.US);
	assertEquals(0, binder.getBindingResult().getErrorCount());
	assertEquals("USD 010.500", binder.getBindingResult().getFieldValue("amount"));
	assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d);
	assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:MoneyFormattingTests.java

示例5: setUp

import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
@Before
public void setUp() {
	DefaultConversionService.addDefaultConverters(conversionService);
	conversionService.setEmbeddedValueResolver(new StringValueResolver() {
		@Override
		public String resolveStringValue(String strVal) {
			if ("${pattern}".equals(strVal)) {
				return "#,##.00";
			}
			else {
				return strVal;
			}
		}
	});
	conversionService.addFormatterForFieldType(Number.class, new NumberStyleFormatter());
	conversionService.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory());
	LocaleContextHolder.setLocale(Locale.US);
	binder = new DataBinder(new TestBean());
	binder.setConversionService(conversionService);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:NumberFormattingTests.java

示例6: setUp

import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
@Before
public void setUp() {
	DefaultConversionService.addDefaultConverters(conversionService);
	conversionService.setEmbeddedValueResolver(new StringValueResolver() {
		@Override
		public String resolveStringValue(String strVal) {
			if ("${pattern}".equals(strVal)) {
				return "#,##.00";
			} else {
				return strVal;
			}
		}
	});
	conversionService.addFormatterForFieldType(Number.class, new NumberFormatter());
	conversionService.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory());
	LocaleContextHolder.setLocale(Locale.US);
	binder = new DataBinder(new TestBean());
	binder.setConversionService(conversionService);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:20,代码来源:NumberFormattingTests.java

示例7: setUp

import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
private void setUp(JodaTimeFormatterRegistrar registrar) {
	conversionService = new FormattingConversionService();
	DefaultConversionService.addDefaultConverters(conversionService);

	registrar.registerFormatters(conversionService);

	JodaTimeBean bean = new JodaTimeBean();
	bean.getChildren().add(new JodaTimeBean());
	binder = new DataBinder(bean);
	binder.setConversionService(conversionService);

	LocaleContextHolder.setLocale(Locale.US);
	JodaTimeContext context = new JodaTimeContext();
	context.setTimeZone(DateTimeZone.forID("-05:00"));
	JodaTimeContextHolder.setJodaTimeContext(context);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:17,代码来源:JodaTimeFormattingTests.java

示例8: testAmountWithNumberFormat2

import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
@Test
public void testAmountWithNumberFormat2() {
	FormattedMoneyHolder2 bean = new FormattedMoneyHolder2();
	DataBinder binder = new DataBinder(bean);
	binder.setConversionService(conversionService);

	MutablePropertyValues propertyValues = new MutablePropertyValues();
	propertyValues.add("amount", "10.50");
	binder.bind(propertyValues);
	assertEquals(0, binder.getBindingResult().getErrorCount());
	assertEquals("10.5", binder.getBindingResult().getFieldValue("amount"));
	assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d);
	assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:15,代码来源:MoneyFormattingTests.java

示例9: testAmountWithNumberFormat4

import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
@Test
public void testAmountWithNumberFormat4() {
	FormattedMoneyHolder4 bean = new FormattedMoneyHolder4();
	DataBinder binder = new DataBinder(bean);
	binder.setConversionService(conversionService);

	MutablePropertyValues propertyValues = new MutablePropertyValues();
	propertyValues.add("amount", "010.500");
	binder.bind(propertyValues);
	assertEquals(0, binder.getBindingResult().getErrorCount());
	assertEquals("010.500", binder.getBindingResult().getFieldValue("amount"));
	assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d);
	assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:15,代码来源:MoneyFormattingTests.java

示例10: setUp

import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
private void setUp(JodaTimeFormatterRegistrar registrar) {
	conversionService = new FormattingConversionService();
	DefaultConversionService.addDefaultConverters(conversionService);
	registrar.registerFormatters(conversionService);

	JodaTimeBean bean = new JodaTimeBean();
	bean.getChildren().add(new JodaTimeBean());
	binder = new DataBinder(bean);
	binder.setConversionService(conversionService);

	LocaleContextHolder.setLocale(Locale.US);
	JodaTimeContext context = new JodaTimeContext();
	context.setTimeZone(DateTimeZone.forID("-05:00"));
	JodaTimeContextHolder.setJodaTimeContext(context);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:JodaTimeFormattingTests.java

示例11: setUp

import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
private void setUp(DateTimeFormatterRegistrar registrar) {
	conversionService = new FormattingConversionService();
	DefaultConversionService.addDefaultConverters(conversionService);
	registrar.registerFormatters(conversionService);

	DateTimeBean bean = new DateTimeBean();
	bean.getChildren().add(new DateTimeBean());
	binder = new DataBinder(bean);
	binder.setConversionService(conversionService);

	LocaleContextHolder.setLocale(Locale.US);
	DateTimeContext context = new DateTimeContext();
	context.setTimeZone(ZoneId.of("-05:00"));
	DateTimeContextHolder.setDateTimeContext(context);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:DateTimeFormattingTests.java

示例12: setUp

import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
private void setUp(DateFormatterRegistrar registrar) {
	DefaultConversionService.addDefaultConverters(conversionService);
	registrar.registerFormatters(conversionService);

	SimpleDateBean bean = new SimpleDateBean();
	bean.getChildren().add(new SimpleDateBean());
	binder = new DataBinder(bean);
	binder.setConversionService(conversionService);

	LocaleContextHolder.setLocale(Locale.US);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:12,代码来源:DateFormattingTests.java

示例13: setup

import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
@Before
public void setup() {
	this.conversionService = new DefaultFormattingConversionService();
	DataBinder dataBinder = new DataBinder(null);
	dataBinder.setConversionService(conversionService);

	this.redirectAttributes = new RedirectAttributesModelMap(dataBinder);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:RedirectAttributesModelMapTests.java

示例14: parseAndPrint

import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
private String parseAndPrint(String name, String value) throws BindException {
	Map<String, String> paramMap = new HashMap<>();
	paramMap.put(name, value);

	Form form = new Form();
	DataBinder binder = new DataBinder(form, "target");
	binder.setConversionService(conversionService);
	binder.bind(new MutablePropertyValues(paramMap));

	BindingResult binding = BindingResultUtils.getBindingResult(binder.close(), "target");
	return (String) binding.getFieldValue(name);
}
 
开发者ID:agwlvssainokuni,项目名称:sqlapp,代码行数:13,代码来源:LocalDateFormatTest.java

示例15: bindData

import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
public void bindData(T target, Map<?, ?> data) {
    DataBinder binder = new DataBinder(target);
    binder.setConversionService(conversionService);
    binder.bind(new MutablePropertyValues(data));
}
 
开发者ID:imCodePartnerAB,项目名称:iVIS,代码行数:6,代码来源:EntityLoader.java


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