0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【SpringBootアノテーション一覧 バリデーション編】

Last updated at Posted at 2025-06-11

バリデーションとはBean Validation を使って入力チェックをする方法。
電話番号は11桁で入力してください。みたいなやつ。ちゃんと入力しないと、送信できないで赤くなるやつ。

@NotNull

必須チェック(NULLの場合NG)

@NotEmpty

必須チェック(NULL、空文字の場合NG)

@Size

import javax.validation.constraints.Size;
@Size(min =2, max = 10, message = "パスワードは2文字以上10文字以下で登録してください")

桁数チェック

@Min

数値の最小値チェック数値の最小値チェック

@Min(value = 18, message = "年齢は18歳以上でなければなりません")
@Max(value = 100, message = "年齢は100歳以下でなければなりません")

メッセージなしの場合は数字だけでいい
@Min(18)
@Max(100)

@Max

数値の最大値チェック

@Pattern

正規表現チェック

@AssertTrue

相関チェック(returnがTrueの場合OK)

@AssertFalse

相関チェック(returnがFalseの場合OK)

@Valid

子クラスでもBean Validationを行いたい場合指定する

こちらを参考にしました!
【Spring Boot】バリデーション

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?