Predictable index position for BindingResult keys and parameter annotation convenience methods in MethodParameter

This commit is contained in:
Rossen Stoyanchev 2011-03-31 14:16:37 +00:00
parent 006cbb25c5
commit 3f11fbafaa
2 changed files with 18 additions and 4 deletions

View File

@ -19,8 +19,8 @@ package org.springframework.validation;
import java.beans.PropertyEditor;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -270,11 +270,11 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
* @see org.springframework.web.servlet.mvc.SimpleFormController
*/
public Map<String, Object> getModel() {
Map<String, Object> model = new HashMap<String, Object>(2);
// Errors instance, even if no errors.
model.put(MODEL_KEY_PREFIX + getObjectName(), this);
Map<String, Object> model = new LinkedHashMap<String, Object>(2);
// Mapping from name to target object.
model.put(getObjectName(), getTarget());
// Errors instance, even if no errors.
model.put(MODEL_KEY_PREFIX + getObjectName(), this);
return model;
}

View File

@ -278,6 +278,20 @@ public class MethodParameter {
return null;
}
/**
* Return true if the parameter has at least one annotation, false if it has none.
*/
public boolean hasParameterAnnotations() {
return getParameterAnnotations().length != 0;
}
/**
* Return true if the parameter has the given annotation type, and false if it doesn't.
*/
public <T extends Annotation> boolean hasParameterAnnotation(Class<T> annotationType) {
return getParameterAnnotation(annotationType) != null;
}
/**
* Initialize parameter name discovery for this method parameter.
* <p>This method does not actually try to retrieve the parameter name at