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