本文整理汇总了Java中org.springframework.validation.FieldError.getDefaultMessage方法的典型用法代码示例。如果您正苦于以下问题:Java FieldError.getDefaultMessage方法的具体用法?Java FieldError.getDefaultMessage怎么用?Java FieldError.getDefaultMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.validation.FieldError
的用法示例。
在下文中一共展示了FieldError.getDefaultMessage方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: build
import org.springframework.validation.FieldError; //导入方法依赖的package包/类
/**
* 只将第一个错误抛出异常
* @param errResult
* @return
*/
public static ValidationException build(BindingResult errResult) {
FieldError fieldError = errResult.getFieldError();
String code = fieldError.getCode();
String field = fieldError.getField();
String message = fieldError.getDefaultMessage();
message = "`" + field + "` " + message;
ErrorCode errorCode = ErrorCodeConfig.PARAM_INVAILD;
switch (code) {
case "NotNull":
errorCode = ErrorCodeConfig.PARAM_NOTFOUND;
break;
case "Length":
errorCode = ErrorCodeConfig.PARAM_INVAILD_LENGTH;
break;
default:
break;
}
return new ValidationException(errorCode, message);
}
示例2: extractedValidationMessage
import org.springframework.validation.FieldError; //导入方法依赖的package包/类
private String extractedValidationMessage(Exception e) {
BindValidationException bindValidationException = (BindValidationException) e.getCause().getCause();
ValidationErrors validationErrors = bindValidationException.getValidationErrors();
FieldError fieldError = (FieldError) validationErrors.getAllErrors().get(0);
return fieldError.getDefaultMessage();
}
示例3: getDefaultMessage
import org.springframework.validation.FieldError; //导入方法依赖的package包/类
private String getDefaultMessage(MethodArgumentNotValidException ex) {
FieldError error = ex.getBindingResult().getFieldError();
ObjectError globalError = ex.getBindingResult().getGlobalError();
if (error == null) {
return globalError.getDefaultMessage();
} else {
return error.getDefaultMessage();
}
}
示例4: FieldErrorDto
import org.springframework.validation.FieldError; //导入方法依赖的package包/类
public FieldErrorDto(FieldError fieldError) {
this.fieldName = fieldError.getField();
this.message = fieldError.getDefaultMessage();
}
示例5: handle
import org.springframework.validation.FieldError; //导入方法依赖的package包/类
@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ResponseEntity handle(MethodArgumentNotValidException e) {
FieldError error = e.getBindingResult().getFieldError();
return new ResponseEntity(400, error.getField()+": "+error.getDefaultMessage(), null);
}
示例6: RestFieldError
import org.springframework.validation.FieldError; //导入方法依赖的package包/类
public RestFieldError(FieldError error) {
this.field = error.getField();
this.rejectedValue = error.getRejectedValue();
this.message = error.getDefaultMessage();
}
示例7: ValidationErrorResource
import org.springframework.validation.FieldError; //导入方法依赖的package包/类
public ValidationErrorResource(FieldError fieldError) {
this.property = fieldError.getField();
this.message = fieldError.getDefaultMessage();
this.invalidValue = String.valueOf(fieldError.getRejectedValue());
}
示例8: processFieldError
import org.springframework.validation.FieldError; //导入方法依赖的package包/类
private Map<String, Object> processFieldError(Map<String, Object> data, Class<?> targetClass, List<FieldError> errors) throws NoSuchFieldException {
for (FieldError error : errors) {
String field = error.getField();
String key = field + error.getCode();
MsgCode msgCode = null;
if (null == errorFields.get(key)) {
String[] pfields = field.split("\\.");
//判断是否为双层对象并进行切割获取字段对象的字段并抓取code
if (pfields.length >= 2) {
String temp = pfields[0];
if (temp.contains("[")) {
temp = temp.substring(0, temp.indexOf("["));
}
Field declaredField = targetClass.getDeclaredField(temp);
Class clazz = declaredField.getType();
if (clazz.isAssignableFrom(List.class) || clazz.isAssignableFrom(Map.class)) {
Type genType = declaredField.getGenericType();
if (!(genType instanceof ParameterizedType)) {
clazz = Object.class;
} else {
Type[] params = ((ParameterizedType) genType).getActualTypeArguments();
try {
clazz = (Class) params[0];
} catch (Exception e) {
try {
clazz = (Class) ((ParameterizedType) params[0]).getRawType();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
}
msgCode = clazz.getDeclaredField(pfields[1]).getAnnotation(MsgCode.class);
} else {
msgCode = targetClass.getDeclaredField(field).getAnnotation(MsgCode.class);
}
errorFields.put(key, msgCode);
} else {
msgCode = errorFields.get(key);
}
if (null != msgCode) {
data.put(CODE_KEY, errorCode.getCode(msgCode.value()));
}
//根据code 在error_code.yml取值,如果未取到值则去默认的error.getDefaultMessage();
String message = errorCode.getMessage(msgCode != null ? msgCode.value() : null);
if (null == message) {
message = error.getDefaultMessage();
}
data.put(MESSAGE_KEY, message);
return data;
}
data.put(CODE_KEY, 1000);
return data;
}
示例9: resolveLocalizedErrorMessage
import org.springframework.validation.FieldError; //导入方法依赖的package包/类
protected String resolveLocalizedErrorMessage(FieldError fieldError) {
if (getMessageSource()!=null) {
return getMessageSource().getMessage(fieldError, LocaleContextHolder.getLocale());
}
return fieldError.getDefaultMessage();
}
示例10: UIErrorDetail
import org.springframework.validation.FieldError; //导入方法依赖的package包/类
UIErrorDetail(FieldError error) {
rejectedValue = error.getRejectedValue();
path = error.getObjectName() + '.' + error.getField();
message = "Invalid value for field '" + error.getField() + "': " + error.getDefaultMessage();
}
示例11: FormErrorDto
import org.springframework.validation.FieldError; //导入方法依赖的package包/类
public FormErrorDto(FieldError fieldError) {
this.field = fieldError.getField();
this.code = fieldError.getCode();
this.message = fieldError.getDefaultMessage();
this.rejectedValue = fieldError.getRejectedValue();
}