S SmartDocs
シリーズ: Springboot java 23 行 · 更新日 2026-08-14

Role.java

Springboot/bookstore-api/src/main/java/com/example/bookstore/entity/Role.java

package com.example.bookstore.entity;

/**
 * 使用者角色(Role)列舉,用於「授權」(Authorization)判斷。
 *
 * 【Spring Security 慣例】
 * 角色名稱必須以 "ROLE_" 開頭。
 * 之後在授權規則中寫 hasRole("ADMIN") 時,
 * Spring Security 會自動加上前綴,比對 "ROLE_ADMIN"。
 *
 * 本專案的權限設計:
 *   - 未登入訪客     :只能「查詢」書籍(GET)
 *   - ROLE_USER      :可查詢、新增、修改書籍(GET / POST / PUT / PATCH)
 *   - ROLE_ADMIN     :擁有全部權限,包含「刪除」書籍(DELETE)
 */
public enum Role {

    /** 一般使用者:可讀取、新增、修改書籍 */
    ROLE_USER,

    /** 管理員:額外擁有刪除書籍的權限 */
    ROLE_ADMIN
}

関連記事

Springboot java EN 更新日 2026-08-14

BookstoreApiApplication.java

BookstoreApiApplication.java — java source code from the Springboot learning materials (Springboot/bookstore-api/src/main/java/com/example/bookstore/BookstoreApiApplication.java).

記事を読む →
Springboot java EN 更新日 2026-08-14

DataInitializer.java

DataInitializer.java — java source code from the Springboot learning materials (Springboot/bookstore-api/src/main/java/com/example/bookstore/config/DataInitializer.java).

記事を読む →
Springboot java EN 更新日 2026-08-14

SecurityConfig.java

SecurityConfig.java — java source code from the Springboot learning materials (Springboot/bookstore-api/src/main/java/com/example/bookstore/config/SecurityConfig.java).

記事を読む →
Springboot java EN 更新日 2026-08-14

AuthController.java

AuthController.java — java source code from the Springboot learning materials (Springboot/bookstore-api/src/main/java/com/example/bookstore/controller/AuthController.java).

記事を読む →
Springboot java EN 更新日 2026-08-14

BookController.java

BookController.java — java source code from the Springboot learning materials (Springboot/bookstore-api/src/main/java/com/example/bookstore/controller/BookController.java).

記事を読む →
Springboot java EN 更新日 2026-08-14

ApiErrorResponse.java

ApiErrorResponse.java — java source code from the Springboot learning materials (Springboot/bookstore-api/src/main/java/com/example/bookstore/dto/ApiErrorResponse.java).

記事を読む →