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?

Spring Menu Manager - Spring Boot用のシンプルなメニュー管理ライブラリ

Posted at

Spring Menu Manager - Spring Boot用のシンプルなメニュー管理ライブラリ

はじめに

Spring Bootアプリケーションでナビゲーションメニューを簡単に管理できるライブラリ「Spring Menu Manager」を紹介します。

主な機能

  • 階層構造のメニュー管理
  • RESTful APIによる操作
  • H2データベースによるデータ永続化
  • Flywayによるマイグレーション管理
  • Spring Boot 3.2.2との完全な互換性

必要条件

  • Java 17以上
  • Gradle 8.5以上
  • Spring Boot 3.2.2

セットアップ方法

Gradleの設定

repositories {
    maven {
        url = uri("https://maven.pkg.github.com/shizuya-aishima/spring-menu-manager")
    }
}

dependencies {
    implementation 'com.github.shizuya-aishima:spring-menu-manager:0.0.1-SNAPSHOT'
}

アプリケーションの設定

@SpringBootApplication
@ComponentScan(basePackages = "com.github.shizuyaaishima.menu")
@EntityScan(basePackages = "com.github.shizuyaaishima.menu.entity")
@EnableJpaRepositories(basePackages = "com.github.shizuyaaishima.menu.repository")
public class YourApplication {
    public static void main(String[] args) {
        SpringApplication.run(YourApplication.class, args);
    }
}

API仕様

主要エンドポイント

  • GET /api/menu: 全メニュー項目の取得
  • GET /api/menu/root: ルートメニュー項目の取得
  • GET /api/menu/sub/{parentId}: サブメニュー項目の取得

レスポンス例

[
  {
    "id": 1,
    "name": "ホーム",
    "url": "/",
    "displayOrder": 1,
    "parentId": null,
    "icon": "home",
    "enabled": true,
    "createdAt": "2024-02-20T10:00:00",
    "updatedAt": "2024-02-20T10:00:00"
  }
]

データベース構造

menu_items テーブル

カラム名 説明
id BIGINT 主キー
name VARCHAR(255) メニュー項目名
url VARCHAR(255) リンク先URL
display_order INT 表示順序
parent_id BIGINT 親メニューのID
icon VARCHAR(255) アイコン名
enabled BOOLEAN 有効/無効フラグ
created_at TIMESTAMP 作成日時
updated_at TIMESTAMP 更新日時

開発者向け情報

ビルドとテスト

# ビルド
./gradlew build

# テスト実行
./gradlew test

# コード品質チェック
./gradlew spotlessCheck
./gradlew pmdMain pmdTest
./gradlew jacocoTestReport

サンプルアプリケーション

./gradlew :menu-sample:bootRun

まとめ

Spring Menu Managerは、Spring Bootアプリケーションにおけるメニュー管理を簡単に実現できるライブラリです。階層構造のメニュー管理やRESTful APIの提供、データベースマイグレーションなど、必要な機能が揃っています。

参考リンク

ライセンス

MIT License


タグ: Java 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?