S SmartDocs
Série: Springboot java 27 linhas · Atualizado 2026-08-14

AuthResponse.java

Springboot/bookstore-api/src/main/java/com/example/bookstore/dto/AuthResponse.java

package com.example.bookstore.dto;

/**
 * 「登入成功」的回應 DTO——把 JWT 交給客戶端。
 *
 * 客戶端收到後應妥善保存 token,
 * 之後每次呼叫受保護的 API 時,都要在 HTTP Header 加上:
 *
 *   Authorization: Bearer <token>
 *
 * 回應範例:
 * {
 *   "token": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyIi...",
 *   "tokenType": "Bearer",
 *   "expiresIn": 3600,
 *   "username": "user",
 *   "role": "ROLE_USER"
 * }
 */
public record AuthResponse(
        String token,      // JWT 字串本體
        String tokenType,  // 固定為 "Bearer"(HTTP 認證方案名稱)
        long expiresIn,    // 有效秒數(方便客戶端判斷何時該重新登入)
        String username,   // 登入者帳號
        String role        // 登入者角色(方便前端顯示對應介面)
) {
}

Artigos relacionados

Springboot java EN Atualizado 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).

Ler artigo →
Springboot java EN Atualizado 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).

Ler artigo →
Springboot java EN Atualizado 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).

Ler artigo →
Springboot java EN Atualizado 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).

Ler artigo →
Springboot java EN Atualizado 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).

Ler artigo →
Springboot java EN Atualizado 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).

Ler artigo →