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})