Giter VIP home page Giter VIP logo

crud-spring-boot-h2database's Introduction

Simple CRUD Example with H2 Database and Spring Boot

This is a simple CRUD (Create, Read, Update, Delete) application built using Spring Boot and H2 database. The application manages a list of items, allowing basic operations via a RESTful API.

Features

  • Create new items
  • Retrieve all items
  • Retrieve a single item by ID
  • Update an existing item
  • Delete an item by ID
  • In-memory H2 database for easy setup and testing

Technologies Used

  • Java
  • Spring Boot
  • Spring Data JPA
  • H2 Database
  • Maven

Getting Started

Prerequisites

  • Java 11 or higher
  • Maven

Running the Application

  1. Clone the repository:

    git clone https://github.com/yourusername/crud-example.git
    cd crud-example
  2. Build and run the application:

    ./mvnw spring-boot:run
  3. Access the H2 database console:

    • URL: http://localhost:8009/h2-console
    • JDBC URL: jdbc:h2:mem:testdb
    • Username: sa
    • Password: (leave it empty)

API Endpoints

  • Create a new item

    • URL: POST /api/items
    • Request Body:
      {
          "name": "Item Name",
          "description": "Item Description"
      }
    • Response:
      {
          "id": 1,
          "name": "Item Name",
          "description": "Item Description"
      }
  • Retrieve all items

    • URL: GET /api/items
    • Response:
      [
          {
              "id": 1,
              "name": "Item Name",
              "description": "Item Description"
          }
      ]
  • Retrieve a single item by ID

    • URL: GET /api/items/{id}
    • Response:
      {
          "id": 1,
          "name": "Item Name",
          "description": "Item Description"
      }
  • Update an existing item

    • URL: PUT /api/items/{id}
    • Request Body:
      {
          "name": "Updated Item Name",
          "description": "Updated Item Description"
      }
    • Response:
      {
          "id": 1,
          "name": "Updated Item Name",
          "description": "Updated Item Description"
      }
  • Delete an item by ID

    • URL: DELETE /api/items/{id}
    • Response: 204 No Content

Project Structure

crud-spring-boot-h2database's People

Contributors

matiasdev30 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.