类 BeanWrapperFieldSetMapper<T>

  • 所有已实现的接口:
    FieldSetMapper<T>, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.InitializingBean, org.springframework.beans.PropertyEditorRegistrar

    public class BeanWrapperFieldSetMapper<T>
    extends DefaultPropertyEditorRegistrar
    implements FieldSetMapper<T>, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.InitializingBean
    FieldSetMapper implementation based on bean property paths. The FieldSet to be mapped should have field name meta data corresponding to bean property paths in an instance of the desired type. The instance is created and initialized either by referring to a prototype object by bean name in the enclosing BeanFactory, or by providing a class to instantiate reflectively.

    Nested property paths, including indexed properties in maps and collections, can be referenced by the FieldSet names. They will be converted to nested bean properties inside the prototype. The FieldSet and the prototype are thus tightly coupled by the fields that are available and those that can be initialized. If some of the nested properties are optional (e.g. collection members) they need to be removed by a post processor.

    To customize the way that FieldSet values are converted to the desired type for injecting into the prototype there are several choices. You can inject PropertyEditor instances directly through the customEditors property, or you can override the createBinder(Object) and initBinder(DataBinder) methods, or you can provide a custom FieldSet implementation. You can also use a ConversionService to convert to the desired type through the conversionService property.

    Property name matching is "fuzzy" in the sense that it tolerates close matches, as long as the match is unique. For instance:
    • Quantity = quantity (field names can be capitalised)
    • ISIN = isin (acronyms can be lower case bean property names, as per Java Beans recommendations)
    • DuckPate = duckPate (capitalisation including camel casing)
    • ITEM_ID = itemId (capitalisation and replacing word boundary with underscore)
    • ORDER.CUSTOMER_ID = order.customerId (nested paths are recursively checked)
    The algorithm used to match a property name is to start with an exact match and then search successively through more distant matches until precisely one match is found. If more than one match is found there will be an error.
    作者:
    Dave Syer
    • 方法概要

      所有方法 实例方法 具体方法 
      修饰符和类型方法说明
      voidafterPropertiesSet()
      Check that precisely one of type or prototype bean name is specified.
      protected org.springframework.validation.DataBindercreateBinder​(java.lang.Object target)
      Create a binder for the target object.
      protected voidinitBinder​(org.springframework.validation.DataBinder binder)
      Initialize a new binder instance.
      TmapFieldSet​(FieldSet fs)
      Map the FieldSet to an object retrieved from the enclosing Spring context, or to a new instance of the required type if no prototype is available.
      voidsetBeanFactory​(org.springframework.beans.factory.BeanFactory beanFactory) 
      voidsetConversionService​(org.springframework.core.convert.ConversionService conversionService)
      Public setter for the 'conversionService' property.
      voidsetCustomEditors​(java.util.Map<? extends java.lang.Object,​? extends java.beans.PropertyEditor> customEditors)
      Specify the custom editors to register.
      voidsetDistanceLimit​(int distanceLimit)
      The maximum difference that can be tolerated in spelling between input key names and bean property names.
      voidsetPrototypeBeanName​(java.lang.String name)
      The bean name (id) for an object that can be populated from the field set that will be passed into mapFieldSet(FieldSet).
      voidsetStrict​(boolean strict)
      Public setter for the 'strict' property.
      voidsetTargetType​(java.lang.Class<? extends T> type)
      Public setter for the type of bean to create instead of using a prototype bean.
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 方法详细资料

      • setBeanFactory

        public void setBeanFactory​(org.springframework.beans.factory.BeanFactory beanFactory)
        指定者:
        setBeanFactory 在接口中 org.springframework.beans.factory.BeanFactoryAware
      • setDistanceLimit

        public void setDistanceLimit​(int distanceLimit)
        The maximum difference that can be tolerated in spelling between input key names and bean property names. Defaults to 5, but could be set lower if the field names match the bean names.
        参数:
        distanceLimit - the distance limit to set
      • setPrototypeBeanName

        public void setPrototypeBeanName​(java.lang.String name)
        The bean name (id) for an object that can be populated from the field set that will be passed into mapFieldSet(FieldSet). Typically a prototype scoped bean so that a new instance is returned for each field set mapped. Either this property or the type property must be specified, but not both.
        参数:
        name - the name of a prototype bean in the enclosing BeanFactory
      • setTargetType

        public void setTargetType​(java.lang.Class<? extends T> type)
        Public setter for the type of bean to create instead of using a prototype bean. An object of this type will be created from its default constructor for every call to mapFieldSet(FieldSet).
        Either this property or the prototype bean name must be specified, but not both.
        参数:
        type - the type to set
      • afterPropertiesSet

        public void afterPropertiesSet()
                                throws java.lang.Exception
        Check that precisely one of type or prototype bean name is specified.
        指定者:
        afterPropertiesSet 在接口中 org.springframework.beans.factory.InitializingBean
        抛出:
        java.lang.IllegalStateException - if neither is set or both properties are set.
        java.lang.Exception
        另请参阅:
        InitializingBean.afterPropertiesSet()
      • mapFieldSet

        public T mapFieldSet​(FieldSet fs)
                      throws org.springframework.validation.BindException
        Map the FieldSet to an object retrieved from the enclosing Spring context, or to a new instance of the required type if no prototype is available.
        指定者:
        mapFieldSet 在接口中 FieldSetMapper<T>
        参数:
        fs - the FieldSet to map
        返回:
        the populated object
        抛出:
        org.springframework.validation.BindException - if there is a type conversion or other error (if the DataBinder from createBinder(Object) has errors after binding).
        org.springframework.beans.NotWritablePropertyException - if the FieldSet contains a field that cannot be mapped to a bean property.
        另请参阅:
        FieldSetMapper.mapFieldSet(FieldSet)
      • setStrict

        public void setStrict​(boolean strict)
        Public setter for the 'strict' property. If true, then mapFieldSet(FieldSet) will fail of the FieldSet contains fields that cannot be mapped to the bean.
        参数:
        strict - indicator
      • setConversionService

        public void setConversionService​(org.springframework.core.convert.ConversionService conversionService)
        Public setter for the 'conversionService' property. createBinder(Object) will use it if not null.
        参数:
        conversionService - ConversionService to be used for type conversions
      • setCustomEditors

        public void setCustomEditors​(java.util.Map<? extends java.lang.Object,​? extends java.beans.PropertyEditor> customEditors)
        Specify the custom editors to register.
        覆盖:
        setCustomEditors 在类中 DefaultPropertyEditorRegistrar
        参数:
        customEditors - a map of Class to PropertyEditor (or class name to PropertyEditor).
        另请参阅:
        CustomEditorConfigurer.setCustomEditors(Map)