LoginSignup
0
0

More than 1 year has passed since last update.

データの変換と検証(WebDataBinder)

Posted at

WebDataBinder : データのタイプを変換し、検証もしてくれる。

1.データの変換
(1)PropertyEditor : 双方向タイプ変換 (タイプ↔String)。特定のタイプまたは名前のフィールドに
          適用可能。プログラム内で提供するDefault PEと、
          ユーザーが直接登録可能なCustom PEがある。
          種類(https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/beans/propertyeditors/package-summary.html)
(2)Converter : 単方向タイプ変換(タイプA→タイプB)。PEの欠点を改善することによって
        安全性が良くなった(stateful→stateless)。
(3)ConversionService 複数のConverterを登録しておいたもの。タイプ変換サービスを提供。
(4)Formatter : 双方向タイプ変換 (タイプ↔String)。
        @NumberFormat@DateTimeFormatなどのアノテーション。

 処理優先順位はCustom PE、ConversionService、Default PEの順。

2.データ検証
(1)Validator : オブジェクトを検証するためのInterface。
   Global Validator:1つのValidatorで複数のオブジェクトを検証するとき登録して使用する。
(2)MessageSource:ファイル、配列などのさまざまなリソースからメッセージを読み取るための
          Interface。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0