Automatic creation of simple CRUD API of Spring boot and JPA project.

Overview

fast-crud

Automatic creation of simple CRUD API of Spring boot and JPA project.


How to use

Step 1. Add the dependency.

Gradle (build.gradle)
repositories {
   maven { url 'https://jitpack.io' }
}
dependencies {
   implementation 'com.github.ecsimsw:fast-crud:0.0.2'
}
Maven (pom.xml)
<repositories>
    <repository>
        <id>jitpack.ioid>
        <url>https://jitpack.iourl>
    repository>
repositories>
<dependency>
    <groupId>com.github.ecsimswgroupId>
    <artifactId>fast-crudartifactId>
    <version>0.0.2version>
dependency>

Step 2. Put @CRUD on your entity class.

@CRUD
@Enity
class Sample {
}

Step 3. Declare JpaRepository with entity name.

public interface SampleRepository extends JpaRepository<Sample, Long> {}

Step 4. That's it. You just made basic CRUD http api bellow.

HttpMethod Path RequestBody (Json)
save POST /{entityName} O
findAll GET /{entityName} X
findById GET /{entityName}/{id} X
update PUT /{entityName}/{id} O
delete DELETE /{entityName}/{id} X

Step 5. Example

@CRUD
@Entity
public class Sample {

    @GeneratedValue
    @Id
    private Long id;
    private String name;
    
    public Sample() {
    }
    
    public Sample(String name) {
        this.name = name;
    }

    public Long getId() {
        return id;
    }

    public String getName() {
        return name;
    }
}
public interface SampleRepository extends JpaRepository<Sample, Long> {}
[POST] localhost:8080/sample 
{
    "name" : "ecsimsw"
}
[PUT] localhost:8080/sample/1 
{
    "name" : "new_name"
}
[GET] localhost:8080/sample 
[GET] localhost:8080/sample/1
[DELETE] localhost:8080/sample/1

Additional features

Repository name

You can set your repository bean name in @CRUD with repositoryBean parameter.

@CRUD(repositoryBean = "anotherName")
public interface AnotherName extends JpaRepository<Sample, Long> {}

API root path

You can set your api root path

@CRUD(rootPath = "anotherRoot")
/anotherRoot 
/anotherRoot/{id} 

Exclude method

Method can be excluded in @CRUD with exclude parameter.

@CRUD(exclude = {CrudMethod.UPDATE, CrudMethod.DELETE})
You might also like...

Spring JPA Native Query example in Spring Boot

Spring JPA Native Query example in Spring Boot

Nov 30, 2022

Um sistema de hospital feito em Spring Boot, contendo alguns CRUD's, e utilizando algumas famosas dependências, como o Hibernate. Vale destacar a interface inspirada no jogo Minecraft.

Um sistema de hospital feito em Spring Boot, contendo alguns CRUD's, e utilizando algumas famosas dependências, como o Hibernate. Vale destacar a interface inspirada no jogo Minecraft.

Introdução ✏ Esse projeto é uma atividade da disciplina de Design, Arquitetura e Construção de Software [DACS]. O objetivo do projeto é simular um sis

Nov 6, 2022

Caches datapack- and server resources to make world creation faster.

antiresourcereload Caches datapack- and server resources to make world creation faster. Legalisation Status Legal (1.0.2) Description I found out abou

Nov 18, 2022

This is a Maven plugin designed to help developers automatizing the creation of code classes from YML files based on AsyncApi and OpenAPI.

SCS MultiApi Maven Plugin This is a Maven plugin designed to help developers automatizing the creation of code classes from YML files based on AsyncAp

Dec 20, 2022

A code sharing platform built using spring boot, hibernate and JPA as ORM with PostgreSQL which also follows a RESTful architecture.

Snap-Snippet A code sharing platform built using spring boot, hibernate and JPA as ORM with PostgreSQL which also follows a RESTful architecture. Tech

Nov 29, 2022

This project shows how to configure basic auth to secure our rest API and basic transaction on Data JPA

This project shows how to configure basic auth to secure our rest API and basic transaction on Data JPA

Basic Atuthentication Spring Boot Data JPA, MySQL This project shows how to configure basic auth to secure our rest API and basic transaction on Data

Feb 10, 2022

A networking library for LibGDX utilizing Netty allowing easy creation of multiplayer games.

Lunar What is Lunar? Lunar is a networking library for LibGDX. With lunar you can easily create multiplayer games quickly and efficiently. Lunar provi

Nov 25, 2022

This is simple project to show how to create a basic API using Java 11 + Maven + Spring Boot + PostgrSQL + Flyway.

This is simple project to show how to create a basic API using Java 11 + Maven + Spring Boot + PostgrSQL + Flyway.

Dec 10, 2022

Sample Spring-Cloud-Api-Gateway Project of Spring Boot

Sample-Spring-Cloud-Api-Gateway Sample Spring-Cloud-Api-Gateway Project of Spring Boot Proejct Stack Spring Webflux Spring Cloud Gateway Spring Data R

Jan 17, 2022
Comments
  • 예외 처리 정교화

    예외 처리 정교화

    체크 리스트

    • 이미 같은 path의 API가 존재하는 경우
    • {entityName}Repository 빈이 존재하지 않는 경우
    • {entityName}Repository 빈이 JpaRepository 타입이 아닌 경우
    • @Id 필드가 존재하지 않는 경우
    • @Entity가 붙어있지 않은 경우
    • id path가 Long으로 파싱이 안되는 경우
    • id에 해당하는 entity 데이터가 존재하지 않는 경우
    • 요청 body가 entity로 매핑에 안되는 경우
    opened by ecsimsw 1
  • RequestBody to Entity mapping 정교화

    RequestBody to Entity mapping 정교화

    다음 경우를 확인한다.

    1. Entity 필드에 외부 Class가 존재하는 경우
    2. List, Set 등 컬렉션이 넘어오는 경우
    3. 필드가 부족한채로 넘어오거나, 존재하지 않는 필드가 body에 있는 상태로 넘어오는 경우
    4. Id가 포함된 생성 요청이 들어오는 경우, 넘어온 id를 무시하고 Update가 아닌 Create로 처리
    opened by ecsimsw 1
Releases(0.0.2)
Owner
JinHwanKim
JinHwanKim
Spring Boot JdbcTemplate example with SQL Server: CRUD Rest API using Spring Data JDBC, Spring Web MVC

Spring Boot JdbcTemplate example with SQL Server: Build CRUD Rest API Build a Spring Boot CRUD Rest API example that uses Spring Data Jdbc to make CRU

null 7 Dec 20, 2022
该仓库中主要是 Spring Boot 的入门学习教程以及一些常用的 Spring Boot 实战项目教程,包括 Spring Boot 使用的各种示例代码,同时也包括一些实战项目的项目源码和效果展示,实战项目包括基本的 web 开发以及目前大家普遍使用的线上博客项目/企业大型商城系统/前后端分离实践项目等,摆脱各种 hello world 入门案例的束缚,真正的掌握 Spring Boot 开发。

Spring Boot Projects 该仓库中主要是 Spring Boot 的入门学习教程以及一些常用的 Spring Boot 实战项目教程,包括 Spring Boot 使用的各种示例代码,同时也包括一些实战项目的项目源码和效果展示,实战项目包括基本的 web 开发以及目前大家普遍使用的前

十三 4.5k Dec 30, 2022
Dynamically filters JPA entities with a simple query syntax. Provides JPA/Hibernate predicates and Spring Data specifications.

Spring Filter You need a way to dynamically filter entities without any effort? Just add me to your pom.xml. Your API will gain a full featured search

Turkraft 142 Dec 13, 2022
循序渐进,学习Spring Boot、Spring Boot & Shiro、Spring Batch、Spring Cloud、Spring Cloud Alibaba、Spring Security & Spring Security OAuth2,博客Spring系列源码:https://mrbird.cc

Spring 系列教程 该仓库为个人博客https://mrbird.cc中Spring系列源码,包含Spring Boot、Spring Boot & Shiro、Spring Cloud,Spring Boot & Spring Security & Spring Security OAuth2

mrbird 24.8k Jan 6, 2023
UMS is a CRUD based management system which uses File Handling to manipulate data and perform the CRUD operations

UMS is a CRUD (Create, Read, Update, Delete) based management system which uses File Handling to manipulate data and perform the CRUD operations. It is a group project made using Java procedural programming having both User and Admin sides.

Daoud-Hussain 9 Dec 20, 2022
Spring Boot JWT Authentication example with Spring Security & Spring Data JPA

Spring Boot JWT Authentication example with Spring Security & Spring Data JPA

null 1 Jan 26, 2022
In this project, we will implement two Spring Boot Java Web application called, streamer-data-jpa and streamer-data-r2dbc.

In this project, we will implement two Spring Boot Java Web application called, streamer-data-jpa and streamer-data-r2dbc. They both will fetch 1 million of customer's data from MySQL and stream them to Kafka. The main goal is to compare the application's performance and resource utilization.

Ivan Franchin 6 Nov 2, 2022
Spring Boot Login and Registration example with MySQL, JWT, Rest Api - Spring Boot Spring Security Login example

Spring Boot Login example with Spring Security, MySQL and JWT Appropriate Flow for User Login and Registration with JWT Spring Boot Rest Api Architect

null 58 Jan 5, 2023
An examples of creating test records in the database with Spring Boot + Spring Data + JPA usage.

Spring Boot + JPA — Clear Tests An examples of creating test records in the database with Spring Boot + Spring Data + JPA usage. Check out the article

Semyon Kirekov 8 Nov 24, 2022
Spring JPA @Query for custom query in Spring Boot example

Spring JPA @Query example (Custom query) in Spring Boot Use Spring JPA @Query for custom query in Spring Boot example: Way to use JPQL (Java Persisten

null 17 Dec 3, 2022