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?

MVCモデル

Last updated at Posted at 2025-07-10

MVCモデルは、アプリケーションの設計パターン

M:Model

データ構造とDB処理全般、ビジネスロジックなど

V:Veiw

HTML,templete

C:Controller

requestを受け取って、modelからデータを取り出して、Veiwに返す。

MVC_model.jpg

  1. ユーザーがアプリケーションにリクエストを送信
  2. リクエストはコントローラーによって受け取られる
  3. コントローラーは必要なデータをモデルに要求する
  4. モデルはデータベースからデータを取得する
  5. モデルは情報をコントローラーに返す
  6. コントローラーは取得したデータをビューに渡す
  7. ビューはデータを適切に整形し、ユーザーに表示する

SpringBootでは、

レイヤー クラス名の例 Springアノテーション
Controller StudentController @RestController
Service StudentService @Service
Repository StudentRepository @Repository または @Mapper(MyBatis)

service(ビジネス層),repository(永続下層)は model に属する。

service層は
Controller と Repository との橋渡しで、ControllerはServiceを呼び出し、ServiceがRepositoryを使って処理をする。直接ControllerがRepositoryを使わないことで責任を分離できる。

利点

  • 責任を分けることで、開発、保守、テストがしやすくなる。
  • 再利用可能なコンポーネントにすることで、開発速度があがる。
  • コンポーネント間の疎結合により、チームで開発しやすい。

注意点

  • コンポーネント間の相互作用が煩雑になることがあるので、適切な設計が必要。
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?