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


Java FormattingConversionService类代码示例

本文整理汇总了Java中org.springframework.format.support.FormattingConversionService的典型用法代码示例。如果您正苦于以下问题:Java FormattingConversionService类的具体用法?Java FormattingConversionService怎么用?Java FormattingConversionService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testBindingErrorWithFormatter

import org.springframework.format.support.FormattingConversionService; //导入依赖的package包/类
@Test
public void testBindingErrorWithFormatter() {
	TestBean tb = new TestBean();
	DataBinder binder = new DataBinder(tb);
	FormattingConversionService conversionService = new FormattingConversionService();
	DefaultConversionService.addDefaultConverters(conversionService);
	conversionService.addFormatterForFieldType(Float.class, new NumberStyleFormatter());
	binder.setConversionService(conversionService);
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("myFloat", "1x2");

	LocaleContextHolder.setLocale(Locale.GERMAN);
	try {
		binder.bind(pvs);
		assertEquals(new Float(0.0), tb.getMyFloat());
		assertEquals("1x2", binder.getBindingResult().getFieldValue("myFloat"));
		assertTrue(binder.getBindingResult().hasFieldErrors("myFloat"));
	}
	finally {
		LocaleContextHolder.resetLocaleContext();
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:DataBinderTests.java

示例2: testBindingWithFormatterAgainstList

import org.springframework.format.support.FormattingConversionService; //导入依赖的package包/类
@Test
public void testBindingWithFormatterAgainstList() {
	BeanWithIntegerList tb = new BeanWithIntegerList();
	DataBinder binder = new DataBinder(tb);
	FormattingConversionService conversionService = new FormattingConversionService();
	DefaultConversionService.addDefaultConverters(conversionService);
	conversionService.addFormatterForFieldType(Float.class, new NumberStyleFormatter());
	binder.setConversionService(conversionService);
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("integerList[0]", "1");

	LocaleContextHolder.setLocale(Locale.GERMAN);
	try {
		binder.bind(pvs);
		assertEquals(new Integer(1), tb.getIntegerList().get(0));
		assertEquals("1", binder.getBindingResult().getFieldValue("integerList[0]"));
	}
	finally {
		LocaleContextHolder.resetLocaleContext();
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:DataBinderTests.java

示例3: testBindingErrorWithFormatterAgainstList

import org.springframework.format.support.FormattingConversionService; //导入依赖的package包/类
@Test
public void testBindingErrorWithFormatterAgainstList() {
	BeanWithIntegerList tb = new BeanWithIntegerList();
	DataBinder binder = new DataBinder(tb);
	FormattingConversionService conversionService = new FormattingConversionService();
	DefaultConversionService.addDefaultConverters(conversionService);
	conversionService.addFormatterForFieldType(Float.class, new NumberStyleFormatter());
	binder.setConversionService(conversionService);
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("integerList[0]", "1x2");

	LocaleContextHolder.setLocale(Locale.GERMAN);
	try {
		binder.bind(pvs);
		assertTrue(tb.getIntegerList().isEmpty());
		assertEquals("1x2", binder.getBindingResult().getFieldValue("integerList[0]"));
		assertTrue(binder.getBindingResult().hasFieldErrors("integerList[0]"));
	}
	finally {
		LocaleContextHolder.resetLocaleContext();
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:DataBinderTests.java

示例4: testBindingErrorWithFormatterAgainstFields

import org.springframework.format.support.FormattingConversionService; //导入依赖的package包/类
@Test
public void testBindingErrorWithFormatterAgainstFields() {
	TestBean tb = new TestBean();
	DataBinder binder = new DataBinder(tb);
	binder.initDirectFieldAccess();
	FormattingConversionService conversionService = new FormattingConversionService();
	DefaultConversionService.addDefaultConverters(conversionService);
	conversionService.addFormatterForFieldType(Float.class, new NumberStyleFormatter());
	binder.setConversionService(conversionService);
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("myFloat", "1x2");

	LocaleContextHolder.setLocale(Locale.GERMAN);
	try {
		binder.bind(pvs);
		assertEquals(new Float(0.0), tb.getMyFloat());
		assertEquals("1x2", binder.getBindingResult().getFieldValue("myFloat"));
		assertTrue(binder.getBindingResult().hasFieldErrors("myFloat"));
	}
	finally {
		LocaleContextHolder.resetLocaleContext();
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:DataBinderTests.java

示例5: testDefaultRepositoryConfiguration

import org.springframework.format.support.FormattingConversionService; //导入依赖的package包/类
@Test
public void testDefaultRepositoryConfiguration() throws Exception {
	this.context = new AnnotationConfigWebApplicationContext();
	this.context.setServletContext(new MockServletContext());
	this.context.register(TestConfiguration.class,
			EmbeddedDataSourceConfiguration.class,
			HibernateJpaAutoConfiguration.class,
			JpaRepositoriesAutoConfiguration.class,
			SpringDataWebAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	this.context.refresh();
	assertThat(this.context.getBean(CityRepository.class)).isNotNull();
	assertThat(this.context.getBean(PageableHandlerMethodArgumentResolver.class))
			.isNotNull();
	assertThat(this.context.getBean(FormattingConversionService.class)
			.canConvert(Long.class, City.class)).isTrue();
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:18,代码来源:JpaWebAutoConfigurationTests.java

示例6: testDefaultRepositoryConfiguration

import org.springframework.format.support.FormattingConversionService; //导入依赖的package包/类
@Test
public void testDefaultRepositoryConfiguration() throws Exception {
	this.context = new AnnotationConfigWebApplicationContext();
	this.context.setServletContext(new MockServletContext());
	this.context.register(TestConfiguration.class,
			EmbeddedDataSourceConfiguration.class,
			HibernateJpaAutoConfiguration.class,
			JpaRepositoriesAutoConfiguration.class,
			SpringDataWebAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	this.context.refresh();
	assertNotNull(this.context.getBean(CityRepository.class));
	assertNotNull(this.context.getBean(PageableHandlerMethodArgumentResolver.class));
	assertTrue(this.context.getBean(FormattingConversionService.class)
			.canConvert(Long.class, City.class));
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:17,代码来源:JpaWebAutoConfigurationTests.java

示例7: testBindingErrorWithFormatter

import org.springframework.format.support.FormattingConversionService; //导入依赖的package包/类
public void testBindingErrorWithFormatter() {
	TestBean tb = new TestBean();
	DataBinder binder = new DataBinder(tb);
	FormattingConversionService conversionService = new FormattingConversionService();
	DefaultConversionService.addDefaultConverters(conversionService);
	conversionService.addFormatterForFieldType(Float.class, new NumberFormatter());
	binder.setConversionService(conversionService);
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("myFloat", "1x2");

	LocaleContextHolder.setLocale(Locale.GERMAN);
	try {
		binder.bind(pvs);
		assertEquals(new Float(0.0), tb.getMyFloat());
		assertEquals("1x2", binder.getBindingResult().getFieldValue("myFloat"));
		assertTrue(binder.getBindingResult().hasFieldErrors("myFloat"));
	}
	finally {
		LocaleContextHolder.resetLocaleContext();
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:22,代码来源:DataBinderTests.java

示例8: testBindingWithFormatterAgainstList

import org.springframework.format.support.FormattingConversionService; //导入依赖的package包/类
public void testBindingWithFormatterAgainstList() {
	BeanWithIntegerList tb = new BeanWithIntegerList();
	DataBinder binder = new DataBinder(tb);
	FormattingConversionService conversionService = new FormattingConversionService();
	DefaultConversionService.addDefaultConverters(conversionService);
	conversionService.addFormatterForFieldType(Float.class, new NumberFormatter());
	binder.setConversionService(conversionService);
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("integerList[0]", "1");

	LocaleContextHolder.setLocale(Locale.GERMAN);
	try {
		binder.bind(pvs);
		assertEquals(new Integer(1), tb.getIntegerList().get(0));
		assertEquals("1", binder.getBindingResult().getFieldValue("integerList[0]"));
	}
	finally {
		LocaleContextHolder.resetLocaleContext();
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:21,代码来源:DataBinderTests.java

示例9: testBindingErrorWithFormatterAgainstList

import org.springframework.format.support.FormattingConversionService; //导入依赖的package包/类
public void testBindingErrorWithFormatterAgainstList() {
	BeanWithIntegerList tb = new BeanWithIntegerList();
	DataBinder binder = new DataBinder(tb);
	FormattingConversionService conversionService = new FormattingConversionService();
	DefaultConversionService.addDefaultConverters(conversionService);
	conversionService.addFormatterForFieldType(Float.class, new NumberFormatter());
	binder.setConversionService(conversionService);
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("integerList[0]", "1x2");

	LocaleContextHolder.setLocale(Locale.GERMAN);
	try {
		binder.bind(pvs);
		assertTrue(tb.getIntegerList().isEmpty());
		assertEquals("1x2", binder.getBindingResult().getFieldValue("integerList[0]"));
		assertTrue(binder.getBindingResult().hasFieldErrors("integerList[0]"));
	}
	finally {
		LocaleContextHolder.resetLocaleContext();
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:22,代码来源:DataBinderTests.java

示例10: testBindingErrorWithFormatterAgainstFields

import org.springframework.format.support.FormattingConversionService; //导入依赖的package包/类
public void testBindingErrorWithFormatterAgainstFields() {
	TestBean tb = new TestBean();
	DataBinder binder = new DataBinder(tb);
	binder.initDirectFieldAccess();
	FormattingConversionService conversionService = new FormattingConversionService();
	DefaultConversionService.addDefaultConverters(conversionService);
	conversionService.addFormatterForFieldType(Float.class, new NumberFormatter());
	binder.setConversionService(conversionService);
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("myFloat", "1x2");

	LocaleContextHolder.setLocale(Locale.GERMAN);
	try {
		binder.bind(pvs);
		assertEquals(new Float(0.0), tb.getMyFloat());
		assertEquals("1x2", binder.getBindingResult().getFieldValue("myFloat"));
		assertTrue(binder.getBindingResult().hasFieldErrors("myFloat"));
	}
	finally {
		LocaleContextHolder.resetLocaleContext();
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:23,代码来源:DataBinderTests.java

示例11: setUp

import org.springframework.format.support.FormattingConversionService; //导入依赖的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

示例12: requestMappingHandlerAdapter

import org.springframework.format.support.FormattingConversionService; //导入依赖的package包/类
@Test
public void requestMappingHandlerAdapter() throws Exception {
	RequestMappingHandlerAdapter adapter = mvcConfiguration.requestMappingHandlerAdapter();

	List<HttpMessageConverter<?>> expectedConverters = new ArrayList<HttpMessageConverter<?>>();
	mvcConfiguration.addDefaultHttpMessageConverters(expectedConverters);
	assertEquals(expectedConverters.size(), adapter.getMessageConverters().size());

	ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) adapter.getWebBindingInitializer();
	assertNotNull(initializer);

	ConversionService conversionService = initializer.getConversionService();
	assertNotNull(conversionService);
	assertTrue(conversionService instanceof FormattingConversionService);

	Validator validator = initializer.getValidator();
	assertNotNull(validator);
	assertTrue(validator instanceof LocalValidatorFactoryBean);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:20,代码来源:WebMvcConfigurationSupportTests.java

示例13: setUp

import org.springframework.format.support.FormattingConversionService; //导入依赖的package包/类
@Before
public void setUp() throws Exception{
    testObjectContext = testPersistenceObjectFactory.createTestObjectContext();

    clearAndIndexJudgmentsInSolr(testObjectContext);

    JudgmentsController judgmentsController = new JudgmentsController();
    judgmentsController.setApiSearchService(apiSearchService);
    judgmentsController.setListSuccessRepresentationBuilder(listSuccessRepresentationBuilder);
    judgmentsController.setParametersExtractor(parametersExtractor);
    judgmentsController.setJsonFormatter(jsonFormatter);
    
    judgmentsController.setMinPageSize(3);
    judgmentsController.setMaxPageSize(50);
    
    FormattingConversionService conversionService = new DefaultFormattingConversionService();
    conversionService.addFormatterForFieldAnnotation(new LawJournalEntryCodeFormatterFactory(lawJournalEntryCodeExtractor));

    mockMvc = standaloneSetup(judgmentsController)
            .addInterceptors(new AccessControlHeaderHandlerInterceptor())
            .addInterceptors(new RestrictParamsHandlerInterceptor())
            .setConversionService(conversionService)
            .build();
}
 
开发者ID:CeON,项目名称:saos,代码行数:25,代码来源:JudgmentsControllerTest.java

示例14: setUp

import org.springframework.format.support.FormattingConversionService; //导入依赖的package包/类
@Before
public void setUp(){
    testObjectContext = testPersistenceObjectFactory.createTestObjectContext();

    DumpJudgmentsController dumpJudgmentsController = new DumpJudgmentsController();

    dumpJudgmentsController.setJudgmentEnrichmentDbSearchService(judgmentEnrichmentDbSearchService);
    dumpJudgmentsController.setDumpJudgmentsListSuccessRepresentationBuilder(dumpJudgmentsListSuccessRepresentationBuilder);
    dumpJudgmentsController.setParametersExtractor(parametersExtractor);
    dumpJudgmentsController.setJsonFormatter(jsonFormatter);

    FormattingConversionService conversionService = new DefaultFormattingConversionService();
    conversionService.addFormatterForFieldAnnotation(new DateTimeWithZoneFormatterFactory());

    mockMvc = standaloneSetup(dumpJudgmentsController)
            .setConversionService(conversionService)
            .addInterceptors(new AccessControlHeaderHandlerInterceptor())
            .addInterceptors(new RestrictParamsHandlerInterceptor())
            .build();

}
 
开发者ID:CeON,项目名称:saos,代码行数:22,代码来源:DumpJudgmentsControllerTest.java

示例15: createFormattingConversionService

import org.springframework.format.support.FormattingConversionService; //导入依赖的package包/类
/**
 * Create a FormattingConversionService which use ISO date format, instead of the localized one.
 * @return the FormattingConversionService
 */
public static FormattingConversionService createFormattingConversionService() {
    DefaultFormattingConversionService dfcs = new DefaultFormattingConversionService ();
    DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
    registrar.setUseIsoFormat(true);
    registrar.registerFormatters(dfcs);
    return dfcs;
}
 
开发者ID:torgcrm,项目名称:TorgCRM-Server,代码行数:12,代码来源:TestUtil.java


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