org.springframework.beans.propertyeditors

## 类 CustomDateEditor

- java.lang.Object
- - java.beans.PropertyEditorSupport
  - - org.springframework.beans.propertyeditors.CustomDateEditor

- 所有已实现的接口:
    PropertyEditor

      public class CustomDateEditor
      extends PropertyEditorSupport

  Property editor for `java.util.Date`, supporting a custom `java.text.DateFormat`.

  This is not meant to be used as system PropertyEditor but rather as locale-specific date editor within custom controller code, parsing user-entered number strings into Date properties of beans and rendering them in the UI form.

  In web MVC code, this editor will typically be registered with `binder.registerCustomEditor`.

  从以下版本开始:
    28.04.2003
  作者:
    Juergen Hoeller
  另请参阅:
    `Date`, `DateFormat`, `org.springframework.validation.DataBinder#registerCustomEditor`

- - ### 构造器概要

    构造器
    构造器和说明
    `CustomDateEditor(DateFormat dateFormat, boolean allowEmpty)` Create a new CustomDateEditor instance, using the given DateFormat for parsing and rendering.
    `CustomDateEditor(DateFormat dateFormat, boolean allowEmpty, int exactDateLength)` Create a new CustomDateEditor instance, using the given DateFormat for parsing and rendering.

  - ### 方法概要

    所有方法 实例方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `String` | `getAsText()` Format the Date as String, using the specified DateFormat.
    `void` | `setAsText(String text)` Parse the Date from the given text, using the specified DateFormat.

    - ### 从类继承的方法 java.beans.PropertyEditorSupport

      `addPropertyChangeListener, firePropertyChange, getCustomEditor, getJavaInitializationString, getSource, getTags, getValue, isPaintable, paintValue, removePropertyChangeListener, setSource, setValue, supportsCustomEditor`

    - ### 从类继承的方法 java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 构造器详细资料

    - #### CustomDateEditor

          public CustomDateEditor(DateFormat dateFormat,
                                  boolean allowEmpty)

      Create a new CustomDateEditor instance, using the given DateFormat for parsing and rendering.

      The "allowEmpty" parameter states if an empty String should be allowed for parsing, i.e. get interpreted as null value. Otherwise, an IllegalArgumentException gets thrown in that case.

      参数:
        `dateFormat` - DateFormat to use for parsing and rendering
        `allowEmpty` - if empty strings should be allowed

    - #### CustomDateEditor

          public CustomDateEditor(DateFormat dateFormat,
                                  boolean allowEmpty,
                                  int exactDateLength)

      Create a new CustomDateEditor instance, using the given DateFormat for parsing and rendering.

      The "allowEmpty" parameter states if an empty String should be allowed for parsing, i.e. get interpreted as null value. Otherwise, an IllegalArgumentException gets thrown in that case.

      The "exactDateLength" parameter states that IllegalArgumentException gets thrown if the String does not exactly match the length specified. This is useful because SimpleDateFormat does not enforce strict parsing of the year part, not even with `setLenient(false)`. Without an "exactDateLength" specified, the "01/01/05" would get parsed to "01/01/0005". However, even with an "exactDateLength" specified, prepended zeros in the day or month part may still allow for a shorter year part, so consider this as just one more assertion that gets you closer to the intended date format.

      参数:
        `dateFormat` - DateFormat to use for parsing and rendering
        `allowEmpty` - if empty strings should be allowed
        `exactDateLength` - the exact expected length of the date String

  - ### 方法详细资料

    - #### setAsText

          public void setAsText(@Nullable
                                String text)
                         throws IllegalArgumentException

      Parse the Date from the given text, using the specified DateFormat.
      指定者:
        `setAsText` 在接口中 `PropertyEditor`
      覆盖:
        `setAsText` 在类中 `PropertyEditorSupport`
      抛出:
        `IllegalArgumentException`

    - #### getAsText

          public String getAsText()

      Format the Date as String, using the specified DateFormat.
      指定者:
        `getAsText` 在接口中 `PropertyEditor`
      覆盖:
        `getAsText` 在类中 `PropertyEditorSupport`