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?

More than 5 years have passed since last update.

SpringBootのタスク管理ツールで使用したアノテーションたち

Posted at

概要

UdemyのReactとSpring Bootを使ってタスク管理ツールを作るコースをやっていて、アノテーションが全然わからなかったので使用したアノテーションをまとめていきます。

使用したアノテーションたち

Controller.java

アノテーション 意味
@RestController WebAPIのエントリポイントとなるクラスを作る場合に使用
@RequestMapping パスやHTTPメソッドのマッピングをする
@CrossOrigin CORSの設定で、アクセス許可する
@PostMappting POSTリクエスト用のアノテーション
@GetMapping GETリクエスト用のアノテーション
@DeleteMapping DELETEリクエスト用のアノテーション
@PatchMapping PATCHリクエスト用のアノテーション 

Service.java

アノテーション 意味
@Service アプリ起動時にSpringBootのコンテナが管理
@Autowired beanをインジェクトする

Repository.java

アノテーション 意味
@Repository アプリ起動時にSpringBootのコンテナが管理
@Override 必ずメソッドをオーバーライドを行う

Exception.java

アノテーション 意味
@ControllerAdvice Controller専用の特殊なメソッド(@Exceptionhandlerなど)を@RestControllerを付与したクラスで共有できる
@RestController Controllerとして認識
@ExceptionHandler Controllerクラス内で発生した例外に対する設定を行うことができる
@ResponseStatus HTTPステータスコードを設定する

Domain.java

アノテーション 意味
@Entity JPAエンティティーであることを定義
@Id @GeneratedValueを適応させる
@GeneratedValue 主キーを生成する
@OneToOne 1対1の関係を作れる。カスケードも指定できる
@OneToMany 1対多の関係をれる。カスケードも指定できる
@ManytoOne 多対1の関係を作れる。カスケードも指定できる
@JoinColumn カラムを追加する際に使用
@JsonIgnore Json出力の対象外となる
@NotBlank 必須。null、空文字、スペースは入れられない
@Size 文字数制限をかけられる
@Column カラムの設定ができる
@JsonFormat 出力したいフォーマットに変換して、出力できる
@PrePersist オブジェクトの永続化前に実行する処理を指定
@PreUpdate オブジェクトの属性が更新前に実行する処理を指定
0
0
1

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?