本文へスキップ
製品デスクトップツールTASTECAD図面の確認TASTEFILESファイル管理TASTEFTPファイル転送TASTESSHリモートワークスペースTASTEZIP圧縮と展開TASTEWINMファイル管理開発ツールTASTECODERust 統合開発環境TASTESTUDIO統合開発・テスト環境TASTEETLデータ統合(ETL)サーバーTASTEREMOTEリモートデスクトップサーバーTASTEGEO空間情報サーバーTASTEMAILメールワークスペース投資TASTESTOCK株式自動売買デスクトップアプリはじめるダウンロードドキュメント購入すべての製品
マーケットプレイス
ニュース
技術ニュース今日の開発ニュース開発ドキュメントプログラミング言語RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWebフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngularサーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Expressアプリ・デスクトップ フレームワークTauriFlutterReact NativeElectronアルゴリズムアルゴリズムの基礎主要アルゴリズム発展アルゴリズム実務のアルゴリズム
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケースコミュニティガイド
協業技術移転ウェブサイト構築デスクトップアプリ構築リリース・決済パイプライン販売パートナーお問い合わせ
サービスリモートデスクトップインストールパッケージのカスタマイズ
TASTEDEV
製品

デスクトップツール

TASTECAD複雑な図面を、軽やかにひらくTASTEFILES必要なファイルだけを、最速でTASTEFTPファイルが行き交う、いちばん端正な道TASTESSHサーバーとあなたを、より確かにつなぐTASTEZIPより速くまとめ、より安全にひらくTASTEWINM2つの画面で整理する、キーボード中心のファイルマネージャー

開発ツール

TASTECODERust アプリの編集・ビルド・デバッグ・テストまでひとつのウィンドウでTASTESTUDIO編集からリモートテスト、承認した AI 修正までTASTEETL値を見ながら、データを運ぶ

サーバー

TASTEREMOTE自社サーバーで運用するリモートデスクトップTASTEGEOGeoServer 互換の空間情報サーバーを Rust で作り直しますTASTEMAILメールの主導権を、もう一度自分の手に

投資

TASTESTOCKいつ・何を。自分で決めたルールどおりに動く株式自動売買

はじめる

ダウンロード全製品の最新版ドキュメント各製品の使い方購入サブスクリプション・永久ライセンスすべての製品全製品を一覧で
すべての製品
マーケットプレイスニュース
技術

ニュース

今日の開発ニュース言語・フレームワーク・GitHub・AI の公式発表開発ドキュメント言語・フレームワーク・アルゴリズムのガイド

プログラミング言語

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

フレームワーク

Webフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngular
サーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
アプリ・デスクトップ フレームワークTauriFlutterReact NativeElectron

アルゴリズム

アルゴリズムの基礎計算量解析 · ソート · 探索 · 基本データ構造 · 木構造とヒープ主要アルゴリズムグラフ探索 · 最短経路と最小全域木 · 動的計画法 · 貪欲法 · 分割統治法 · バックトラッキング発展アルゴリズム文字列アルゴリズム · 数学と整数論 · ビット演算 · セグメント木 · Union-Find実務のアルゴリズムコーディング面接対策 · LRUキャッシュ · レート制限 · コンシステントハッシュ法
開発ドキュメントをすべて見る
コミュニティ
プロジェクトビルダーと作品を探す開発ログ決定と試行錯誤プロンプト再利用できる指示AIツールの問題Claude・Codex・Gemini の問題と回避策ショーケース完成した成果コミュニティガイドオープンにつくる方法
協業
技術移転Rust・egui でネイティブアプリを作るウェブサイト構築10言語、アカウント、ドキュメントとダウンロードデスクトップアプリ構築Rust・egui、WebView なしリリース・決済パイプライン署名・MSI・deb・rpm・AppImage・ハッシュ販売パートナー紹介して決済額の30%お問い合わせ構築・提携・投資のご相談
サービス
リモートデスクトップブラウザから自分のパソコンへインストールパッケージのカスタマイズ必要な機能だけ、設定は事前に
購入
JA
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
ログイン
ログイン
TASTEDEV

小さなツールから、より良い開発へ。

support@tastedev.netTASTEDEVを支援
製品製品ラインナップ購入ドキュメントダウンロードマーケットプレイスサポート
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケース
ポリシー会社概要プライバシーポリシー利用規約サブスクリプション規約返金ポリシーコミュニティガイドライン
アカウントログイン新規登録
訪問者
今日
昨日
累計閲覧
商号
GXSOFT
代表者
CHOI YOUNG GU
事業者登録番号
853-44-00368
所在地
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
電話
+82-10-4404-1523
メール
whitecalvin@tastedev.net
個人情報保護責任者
CHOI YOUNG GU

© 2026 TASTEDEV製品情報は検証済みの開発ソースに基づいています。リリース・改善中

Spring Boot ドキュメント
Spring Boot
Getting Started with Spring BootProject Structure and ConfigurationCore ConceptsData and StateTestingDeployment
ディスカッション

Spring Boot ガイド · 4/6

Data and State

この章は現在、英語でのみ提供しています。

A Spring Boot server usually keeps no state in memory between requests; it lives in a database. This chapter shows how to work with data through Spring Data JPA, keep it consistent with transactions, validate input and manage the schema with Flyway.

Dependencies and connection settings

For PostgreSQL, add these dependencies (in Initializr: data-jpa, postgresql, flyway and validation):

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    implementation("org.springframework.boot:spring-boot-starter-validation")
    implementation("org.springframework.boot:spring-boot-starter-flyway")
    implementation("org.flywaydb:flyway-database-postgresql")
    runtimeOnly("org.postgresql:postgresql")
}

Connection details go under spring.datasource.*. Let Flyway own the schema and have Hibernate only check that entities match the tables:

spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/demo
    username: demo
    password: ${DB_PASSWORD}
  jpa:
    hibernate:
      ddl-auto: validate
    open-in-view: false

Entities and repositories

An entity maps to a table row. JPA needs a no-argument constructor, so add a protected one.

@Entity
public class Todo {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(nullable = false, length = 200)
    private String title;

    private boolean done;

    protected Todo() {}

    public Todo(String title) { this.title = title; }

    public void complete() { this.done = true; }

    public Long getId() { return id; }
    public String getTitle() { return title; }
    public boolean isDone() { return done; }
}

For a repository you declare only an interface; Spring Data generates the implementation. JpaRepository provides save, findById, findAll, deleteById and more, and method names can be turned into queries:

public interface TodoRepository extends JpaRepository<Todo, Long> {

    List<Todo> findByDoneFalseOrderByIdAsc();

    @Query("select t from Todo t where lower(t.title) like lower(concat('%', :keyword, '%'))")
    List<Todo> search(@Param("keyword") String keyword);
}

Transactions

The service layer is where operations are grouped into units of work. A @Transactional method opens a transaction on entry, commits on normal return and rolls back on a runtime exception. Changes to an entity loaded inside the transaction are flushed at commit without calling save (dirty checking).

@Service
@Transactional(readOnly = true)
public class TodoService {

    private final TodoRepository repository;

    public TodoService(TodoRepository repository) {
        this.repository = repository;
    }

    public List<Todo> open() {
        return repository.findByDoneFalseOrderByIdAsc();
    }

    @Transactional
    public void complete(Long id) {
        Todo todo = repository.findById(id)
            .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
        todo.complete();
    }
}
この章について質問がありますか?
前の章Core Concepts次の章Testing

Two pitfalls: checked exceptions do not trigger a rollback by default, so use rollbackFor when needed; and because @Transactional works through a proxy, calling another method of the same class directly bypasses it.

Validating input

Put Bean Validation constraints on the request type and @Valid on the controller parameter. Invalid requests are rejected with a 400 response before your method runs.

public record CreateTodo(@NotBlank @Size(max = 200) String title) {}

@PostMapping
public TodoResponse create(@Valid @RequestBody CreateTodo request) {
    return service.create(request.title());
}

To shape the error body, handle MethodArgumentNotValidException in a @RestControllerAdvice and return a ProblemDetail (the RFC 9457 format).

Managing the schema with Flyway

Flyway runs the SQL files in src/main/resources/db/migration in version order and records what it applied in the flyway_schema_history table. On startup it runs only the files that have not been applied yet.

-- src/main/resources/db/migration/V1__create_todo.sql
create table todo (
    id    bigint generated by default as identity primary key,
    title varchar(200) not null,
    done  boolean not null default false
);

Never edit a migration that has already been applied. Add a new file such as V2__add_due_date.sql instead.

Summary

  • An interface extending JpaRepository gives you CRUD operations and derived queries.
  • Put @Transactional on service methods to define transactions.
  • Add constraints to request types and validate them with @Valid.
  • Manage the schema with Flyway migrations and set Hibernate to validate.

コメント 0件

人気のコメント順新しい順

ログイン · ログインするとコメントできます。