本文整理汇总了Java中org.springframework.validation.MessageCodesResolver类的典型用法代码示例。如果您正苦于以下问题:Java MessageCodesResolver类的具体用法?Java MessageCodesResolver怎么用?Java MessageCodesResolver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MessageCodesResolver类属于org.springframework.validation包,在下文中一共展示了MessageCodesResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConstructFromSpringErrors
import org.springframework.validation.MessageCodesResolver; //导入依赖的package包/类
@Test
public void testConstructFromSpringErrors() {
MessageCodesResolver mockMessageCodesResolver = mock(MessageCodesResolver.class);
when(mockMessageCodesResolver.resolveMessageCodes("default.blank.message", "foo", "bar", null)).thenReturn(new String[] {"Property [bar] cannot be blank"});
when(mockMessageCodesResolver.resolveMessageCodes("default.blank.message", "foo", "baz", null)).thenReturn(new String[] {"Property [baz] cannot be blank"});
MapBindingResult errors = new MapBindingResult(new HashMap(), "foo");
errors.setMessageCodesResolver(mockMessageCodesResolver);
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "bar", "default.blank.message");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "baz", "default.blank.message");
JsonCError jsonc = new JsonCError(errors);
assertThat(jsonc.getCode(), is("Property [bar] cannot be blank"));
assertThat(jsonc.getMessage(), is("Field error in object 'foo' on field 'bar': rejected value [null]; codes [Property [bar] cannot be blank]; arguments []; default message [null]"));
List<Map<String,Object>> errorList = jsonc.getErrors();
assertThat((String) errorList.get(0).get("code"), is("Property [bar] cannot be blank"));
assertThat((String) errorList.get(0).get("message"), is("Field error in object 'foo' on field 'bar': rejected value [null]; codes [Property [bar] cannot be blank]; arguments []; default message [null]"));
assertThat((String) errorList.get(1).get("code"), is("Property [baz] cannot be blank"));
assertThat((String) errorList.get(1).get("message"), is("Field error in object 'foo' on field 'baz': rejected value [null]; codes [Property [baz] cannot be blank]; arguments []; default message [null]"));
}
示例2: getMessageCodesResolver
import org.springframework.validation.MessageCodesResolver; //导入依赖的package包/类
public MessageCodesResolver getMessageCodesResolver() {
List<MessageCodesResolver> candidates = new ArrayList<MessageCodesResolver>();
for (WebMvcConfigurer configurer : this.delegates) {
MessageCodesResolver messageCodesResolver = configurer.getMessageCodesResolver();
if (messageCodesResolver != null) {
candidates.add(messageCodesResolver);
}
}
return selectSingleInstance(candidates, MessageCodesResolver.class);
}
示例3: getMessageCodesResolver
import org.springframework.validation.MessageCodesResolver; //导入依赖的package包/类
@Override
public MessageCodesResolver getMessageCodesResolver() {
List<MessageCodesResolver> candidates = new ArrayList<MessageCodesResolver>();
for (WebMvcConfigurer configurer : this.delegates) {
MessageCodesResolver messageCodesResolver = configurer.getMessageCodesResolver();
if (messageCodesResolver != null) {
candidates.add(messageCodesResolver);
}
}
return selectSingleInstance(candidates, MessageCodesResolver.class);
}
示例4: getMessageCodesResolver
import org.springframework.validation.MessageCodesResolver; //导入依赖的package包/类
@SuppressWarnings("serial")
@Override
public MessageCodesResolver getMessageCodesResolver() {
return new DefaultMessageCodesResolver() {
@Override
public String[] resolveMessageCodes(String errorCode, String objectName) {
return new String[] { "custom." + errorCode };
}
};
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:WebMvcConfigurationSupportExtensionTests.java
示例5: testMessageCodesResolver
import org.springframework.validation.MessageCodesResolver; //导入依赖的package包/类
@Test
public void testMessageCodesResolver() {
loadBeanDefinitions("mvc-config-message-codes-resolver.xml");
RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
assertNotNull(adapter);
Object initializer = adapter.getWebBindingInitializer();
assertNotNull(initializer);
MessageCodesResolver resolver = ((ConfigurableWebBindingInitializer) initializer).getMessageCodesResolver();
assertNotNull(resolver);
assertEquals(TestMessageCodesResolver.class, resolver.getClass());
assertEquals(false, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:AnnotationDrivenBeanDefinitionParserTests.java
示例6: getMessageCodesResolver
import org.springframework.validation.MessageCodesResolver; //导入依赖的package包/类
@Override
public MessageCodesResolver getMessageCodesResolver() {
if (this.mvcProperties.getMessageCodesResolverFormat() != null) {
DefaultMessageCodesResolver resolver = new DefaultMessageCodesResolver();
resolver.setMessageCodeFormatter(
this.mvcProperties.getMessageCodesResolverFormat());
return resolver;
}
return null;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:11,代码来源:WebMvcAutoConfiguration.java
示例7: getMessageCodesResolver
import org.springframework.validation.MessageCodesResolver; //导入依赖的package包/类
/**
* Return the strategy to use for resolving errors into message codes.
*/
public final MessageCodesResolver getMessageCodesResolver() {
return this.messageCodesResolver;
}
示例8: getMessageCodesResolver
import org.springframework.validation.MessageCodesResolver; //导入依赖的package包/类
@Override
public MessageCodesResolver getMessageCodesResolver() {
return null;
}
示例9: getMessageCodesResolver
import org.springframework.validation.MessageCodesResolver; //导入依赖的package包/类
/**
* Override this method to provide a custom {@link MessageCodesResolver}.
*/
protected MessageCodesResolver getMessageCodesResolver() {
return null;
}
示例10: getMessageCodesResolver
import org.springframework.validation.MessageCodesResolver; //导入依赖的package包/类
/**
* {@inheritDoc}
* <p>This implementation is empty.
*/
@Override
public MessageCodesResolver getMessageCodesResolver() {
return null;
}
示例11: getMessageCodesResolver
import org.springframework.validation.MessageCodesResolver; //导入依赖的package包/类
@Override
protected MessageCodesResolver getMessageCodesResolver() {
return this.configurers.getMessageCodesResolver();
}
示例12: getMessageCodesResolver
import org.springframework.validation.MessageCodesResolver; //导入依赖的package包/类
/**
* Return the strategy to use for resolving errors into message codes (if any).
*/
public final MessageCodesResolver getMessageCodesResolver() {
return this.messageCodesResolver;
}
示例13: setMessageCodesResolver
import org.springframework.validation.MessageCodesResolver; //导入依赖的package包/类
/**
* Set the strategy to use for resolving errors into message codes.
* Applies the given strategy to all data binders used by this controller.
* <p>Default is {@code null}, i.e. using the default strategy of
* the data binder.
* @see org.springframework.validation.DataBinder#setMessageCodesResolver
*/
public final void setMessageCodesResolver(MessageCodesResolver messageCodesResolver) {
this.messageCodesResolver = messageCodesResolver;
}
示例14: getMessageCodesResolver
import org.springframework.validation.MessageCodesResolver; //导入依赖的package包/类
/**
* Provide a custom {@link MessageCodesResolver} for building message codes
* from data binding and validation error codes. Leave the return value as
* {@code null} to keep the default.
*/
MessageCodesResolver getMessageCodesResolver();
示例15: setMessageCodesResolver
import org.springframework.validation.MessageCodesResolver; //导入依赖的package包/类
/**
* Set the strategy to use for resolving errors into message codes.
* Applies the given strategy to all data binders used by this controller.
* <p>Default is {@code null}, i.e. using the default strategy of
* the data binder.
* @see #createBinder
* @see org.springframework.validation.DataBinder#setMessageCodesResolver
*/
public final void setMessageCodesResolver(MessageCodesResolver messageCodesResolver) {
this.messageCodesResolver = messageCodesResolver;
}