public class ServletRequestDataBinder extends WebDataBinder
DataBinder。許可 / 必須フィールドの指定、カスタムプロパティエディターの登録などのカスタマイズオプションについては、DataBinder/WebDataBinder スーパークラスを参照してください。
カスタム Web コントローラーの手動データバインディングにも使用できます。たとえば、プレーンコントローラーの実装や MultiActionController ハンドラーメソッドなどです。バインディングプロセスごとに ServletRequestDataBinder をインスタンス化し、現在の ServletRequest を引数として bind を呼び出します。
MyBean myBean = new MyBean(); // apply binder to custom target object ServletRequestDataBinder binder = new ServletRequestDataBinder(myBean); // register custom editors, if desired binder.registerCustomEditor(...); // trigger actual binding of request parameters binder.bind(request); // optionally evaluate binding errors Errors errors = binder.getErrors(); ...
bind(javax.servlet.ServletRequest), DataBinder.registerCustomEditor(java.lang.Class<?>, java.beans.PropertyEditor), DataBinder.setAllowedFields(java.lang.String...), DataBinder.setRequiredFields(java.lang.String...), WebDataBinder.setFieldMarkerPrefix(java.lang.String)DEFAULT_FIELD_DEFAULT_PREFIX, DEFAULT_FIELD_MARKER_PREFIXDEFAULT_AUTO_GROW_COLLECTION_LIMIT, DEFAULT_OBJECT_NAME, logger| コンストラクターと説明 |
|---|
ServletRequestDataBinder(ObjectSE target) デフォルトのオブジェクト名で、新しい ServletRequestDataBinder インスタンスを作成します。 |
ServletRequestDataBinder(ObjectSE target, StringSE objectName) 新しい ServletRequestDataBinder インスタンスを作成します。 |
| 修飾子と型 | メソッドと説明 |
|---|---|
protected void | addBindValues(MutablePropertyValues mpvs, ServletRequestEE request) サブクラスがリクエストに追加のバインド値を追加するために使用できる拡張ポイント。 |
void | bind(ServletRequestEE request) 指定されたリクエストのパラメーターをこのバインダーのターゲットにバインドし、マルチパートリクエストの場合はマルチパートファイルもバインドします。 |
void | closeNoCatch() エラーを致命的として扱います。 |
adaptEmptyArrayIndices, bindMultipart, checkFieldDefaults, checkFieldMarkers, doBind, getEmptyValue, getEmptyValue, getFieldDefaultPrefix, getFieldMarkerPrefix, isBindEmptyMultipartFiles, setBindEmptyMultipartFiles, setFieldDefaultPrefix, setFieldMarkerPrefixaddCustomFormatter, addCustomFormatter, addCustomFormatter, addValidators, applyPropertyValues, bind, checkAllowedFields, checkRequiredFields, close, convertIfNecessary, convertIfNecessary, convertIfNecessary, convertIfNecessary, createBeanPropertyBindingResult, createDirectFieldBindingResult, findCustomEditor, getAllowedFields, getAutoGrowCollectionLimit, getBindingErrorProcessor, getBindingResult, getConversionService, getDisallowedFields, getInternalBindingResult, getObjectName, getPropertyAccessor, getPropertyEditorRegistry, getRequiredFields, getSimpleTypeConverter, getTarget, getTypeConverter, getValidator, getValidators, initBeanPropertyAccess, initDirectFieldAccess, isAllowed, isAutoGrowNestedPaths, isIgnoreInvalidFields, isIgnoreUnknownFields, registerCustomEditor, registerCustomEditor, replaceValidators, setAllowedFields, setAutoGrowCollectionLimit, setAutoGrowNestedPaths, setBindingErrorProcessor, setConversionService, setDisallowedFields, setIgnoreInvalidFields, setIgnoreUnknownFields, setMessageCodesResolver, setRequiredFields, setValidator, validate, validatecloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, toStringSE, waitSE, waitSE, waitSEpublic ServletRequestDataBinder(@Nullable ObjectSE target)
target - バインドするターゲットオブジェクト (または、バインダーが単なるパラメーター値の変換に使用される場合は null )DataBinder.DEFAULT_OBJECT_NAMEpublic void bind(ServletRequestEE request)
この呼び出しにより、必須フィールド (コード「必須」) などの基本的なバインディングエラーや、値と Bean プロパティ (コード "typeMismatch" ) の型の不一致を表すフィールドエラーが発生する可能性があります。
マルチパートファイルは、通常の HTTP パラメーターと同様に、パラメーター名によってバインドされます。つまり、"uploadedFile" は "uploadedFile" Bean プロパティにバインドされ、"setUploadedFile" setter メソッドを呼び出します。
マルチパートファイルのターゲットプロパティの型は、MultipartFile、byte[]、または String です。後者の 2 つは、アップロードされたファイルのコンテンツを受け取ります。これらの場合、元のファイル名、コンテンツ型などのすべてのメタデータは失われます。
request - バインドするパラメーターを含むリクエスト (マルチパートにすることができます)MultipartHttpServletRequest, MultipartFile, DataBinder.bind(org.springframework.beans.PropertyValues)protected void addBindValues(MutablePropertyValues mpvs, ServletRequestEE request)
WebDataBinder.doBind(MutablePropertyValues) の前に呼び出されます。デフォルトの実装は空です。mpvs - データバインディングに使用されるプロパティ値 request - 現在のリクエスト public void closeNoCatch()
throws ServletRequestBindingExceptionこのメソッドは、入力が有効でない場合にエラーになる場合にのみ使用してください。これは、たとえばすべての入力がドロップダウンからのものである場合に適切です。
ServletRequestBindingException - バインディングの問題に関する ServletException のサブクラス