本文整理汇总了Java中org.springframework.validation.DataBinder.bind方法的典型用法代码示例。如果您正苦于以下问题:Java DataBinder.bind方法的具体用法?Java DataBinder.bind怎么用?Java DataBinder.bind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.validation.DataBinder
的用法示例。
在下文中一共展示了DataBinder.bind方法的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: testPlaceholdersErrorInNonEnumerable
import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
@Test
public void testPlaceholdersErrorInNonEnumerable() {
TestBean target = new TestBean();
DataBinder binder = new DataBinder(target);
this.propertySources.addFirst(new PropertySource<Object>("application", "STUFF") {
@Override
public Object getProperty(String name) {
return new Object();
}
});
binder.bind(new PropertySourcesPropertyValues(this.propertySources,
(Collection<String>) null, Collections.singleton("name")));
assertThat(target.getName()).isNull();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:PropertySourcesPropertyValuesTests.java
示例6: testFirstCollectionPropertyWinsNestedAttributes
import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
@Test
public void testFirstCollectionPropertyWinsNestedAttributes() throws Exception {
ListTestBean target = new ListTestBean();
DataBinder binder = new DataBinder(target);
Map<String, Object> first = new LinkedHashMap<String, Object>();
first.put("list[0].description", "another description");
Map<String, Object> second = new LinkedHashMap<String, Object>();
second.put("list[0].name", "first name");
second.put("list[0].description", "first description");
second.put("list[1].name", "second name");
second.put("list[1].description", "second description");
this.propertySources.addFirst(new MapPropertySource("s", second));
this.propertySources.addFirst(new MapPropertySource("f", first));
binder.bind(new PropertySourcesPropertyValues(this.propertySources));
target.getList();
assertThat(target.getList()).hasSize(1);
assertThat(target.getList().get(0).getDescription())
.isEqualTo("another description");
assertThat(target.getList().get(0).getName()).isNull();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:21,代码来源:PropertySourcesPropertyValuesTests.java
示例7: testPlaceholdersErrorInNonEnumerable
import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
@Test
public void testPlaceholdersErrorInNonEnumerable() {
TestBean target = new TestBean();
DataBinder binder = new DataBinder(target);
this.propertySources.addFirst(new PropertySource<Object>("application", "STUFF") {
@Override
public Object getProperty(String name) {
return new Object();
}
});
binder.bind(new PropertySourcesPropertyValues(this.propertySources,
(Collection<String>) null, Collections.singleton("name")));
assertEquals(null, target.getName());
}
示例8: testValidation
import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
@Test
public void testValidation() throws BindException{
Employee employee = new Employee();
DataBinder binder = new DataBinder(employee);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue("empId", "AA1000");
pvs.addPropertyValue("empName", "Nobody");
pvs.addPropertyValue("empAge", 10);
binder.bind(pvs);
Validator validator = new EmployeeValidator();
Errors errors = binder.getBindingResult();
validator.validate(employee, errors);
assertFalse(errors.hasFieldErrors("empId"));
assertFalse(errors.hasFieldErrors("empName"));
assertTrue(errors.hasFieldErrors("empAge"));
}
示例9: 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());
}
示例10: 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());
}
示例11: testBindDateWithoutErrorFallingBackToDateConstructor
import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
@Test
public void testBindDateWithoutErrorFallingBackToDateConstructor() {
DataBinder binder = new DataBinder(new JodaTimeBean());
MutablePropertyValues propertyValues = new MutablePropertyValues();
propertyValues.add("date", "Sat, 12 Aug 1995 13:30:00 GMT");
binder.bind(propertyValues);
assertEquals(0, binder.getBindingResult().getErrorCount());
}
示例12: testPlaceholdersBinding
import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
@Test
public void testPlaceholdersBinding() {
TestBean target = new TestBean();
DataBinder binder = new DataBinder(target);
binder.bind(new PropertySourcesPropertyValues(this.propertySources));
assertThat(target.getName()).isEqualTo("bar");
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:8,代码来源:PropertySourcesPropertyValuesTests.java
示例13: testPlaceholdersBindingNonEnumerable
import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
@Test
public void testPlaceholdersBindingNonEnumerable() {
FooBean target = new FooBean();
DataBinder binder = new DataBinder(target);
binder.bind(new PropertySourcesPropertyValues(this.propertySources,
(Collection<String>) null, Collections.singleton("foo")));
assertThat(target.getFoo()).isEqualTo("bar");
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:PropertySourcesPropertyValuesTests.java
示例14: testPlaceholdersBindingWithError
import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
@Test
public void testPlaceholdersBindingWithError() {
TestBean target = new TestBean();
DataBinder binder = new DataBinder(target);
this.propertySources.addFirst(new MapPropertySource("another",
Collections.<String, Object>singletonMap("something", "${nonexistent}")));
binder.bind(new PropertySourcesPropertyValues(this.propertySources));
assertThat(target.getName()).isEqualTo("bar");
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:PropertySourcesPropertyValuesTests.java
示例15: testCollectionProperty
import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
@Test
public void testCollectionProperty() throws Exception {
ListBean target = new ListBean();
DataBinder binder = new DataBinder(target);
Map<String, Object> map = new LinkedHashMap<String, Object>();
map.put("list[0]", "v0");
map.put("list[1]", "v1");
this.propertySources.addFirst(new MapPropertySource("values", map));
binder.bind(new PropertySourcesPropertyValues(this.propertySources));
assertThat(target.getList()).containsExactly("v0", "v1");
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:PropertySourcesPropertyValuesTests.java